title: How can I check if a pixel is green in a RGB image?
body: <p>I'm using opencv and numpy to process some satellite images.</p>
  
  <p>I need to differentiate what is "land" from what is "green" (crops and vegetation).</p>
  
  <p>My question is: <strong>How can I decide which values are close to green in the RGB format?</strong></p>
  
  <p>What I'm doing so far is:</p>
  
  <pre><code>img = cv2.imread('image1.jpg',1)
  mat = np.asarray(img)
  for elemento in mat: 
      for pixel in elemento:
          if pixel[1] &gt; 200: # If the level of green is higher than 200, I change it to black
              pixel[0] = 0
              pixel[1] = 0
              pixel[2] = 0
          else: # If the level of G is lower than 200 I change it to white.
              pixel[0] = 255
              pixel[1] = 255
              pixel[2] = 255
  </code></pre>
  
  <p>This code works, but isn't really useful. I need a more precise manner to decide which RGB values correspond to green and which ones does not.</p>
  
  <p>How can I achieve this?</p>