title: How can I select the right color to threshold an image with OpenCV?
body: <p>I'm trying to select the green color in an image using OpenCV (the method to do it comes from this <a href="https://realpython.com/python-opencv-color-spaces/" rel="nofollow noreferrer">website</a>. The image I'm treating is :</p>
  <p><a href="https://i.stack.imgur.com/WoGsW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WoGsW.png" alt="enter image description here" /></a></p>
  <p>Here is the code I tried to write.</p>
  <pre><code>import cv2
  import matplotlib.pyplot as plt
  import numpy as np
  
  greenhsv = (60, 255, 255)
  green2hsv=(70,100,170)
  g_square = np.full((10, 10, 3), greenhsv, dtype=np.uint8)/255.0
  plt.imshow(hsv_to_rgb(g_square))
  plt.show()
  g1_square = np.full((10, 10, 3), green2hsv, dtype=np.uint8)/255.0
  plt.imshow(hsv_to_rgb(g1_square))
  plt.show()
  
  nucl = cv2.imread('./Pictures/image_nucleation_essai0.png')
  nucl = cv2.cvtColor(nucl, cv2.COLOR_BGR2RGB)
  plt.imshow(nucl)
  plt.show()
  
  hsv_nucl = cv2.cvtColor(nucl, cv2.COLOR_RGB2HSV)
  
  mask = cv2.inRange(hsv_nucl, greenhsv,green2hsv)
  result = cv2.bitwise_and(nucl, nucl, mask=mask)
  plt.imshow(mask, cmap=&quot;gray&quot;)
  plt.show()
  plt.imshow(result)
  plt.show()
  </code></pre>
  <p>The result is :</p>
  <p><a href="https://i.stack.imgur.com/tD8H6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tD8H6.png" alt="enter image description here" /></a> <a href="https://i.stack.imgur.com/EH18x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EH18x.png" alt="enter image description here" /></a></p>
  <p>So the mask did not work.</p>