title: How does filtering out the colors of a hsv image in opencv python work?
body: <p>I am working on a project that needs to identify the shape of an object in a field. My goal right now is to filter out any colors the background could be such as green, brown, or gray. </p>
  
  <pre><code>import cv2
  import numpy as np
  
  img = cv2.imread('pic1.png')
  hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
  
  lower_green = np.array([0,0, 150])
  upper_green = np.array([255, 255, 255])
  
  mask = cv2.inRange(hsv, lower_green, upper_green)
  res = cv2.bitwise_and(img, img, mask=mask)
  
  cv2.imshow('res1.png', res)
  cv2.waitKey(0)
  </code></pre>
  
  <p>The image </p>
  
  <p><img src="https://i.stack.imgur.com/Ga3Mlm.png" alt="enter image description here]"></p>
  
  <p>is showing a sample of the shapes in the field.</p>
  
  <p>This code results in this image:</p>
  
  <p><img src="https://i.stack.imgur.com/1JKfFm.png" alt="enter image description here]"> </p>
  
  <p>Why do the values I use for the lower and upper greens remove all the green when I have only included red values?</p>
  
  <p>Are there any ways to get filters that remove only one color so I am able to pick and choose which colors I would want to keep and which to remove?</p>