I am working on a project to detect and recognize signs in images from the LISA Traffic Sign Dataset. Since the images are very noisy (in regard to background) I am trying to segment the signs based on their color using HSV and cv2.inRange().

The problem I am running into is my algorithm is segmenting far too much of the image. For example, when I try to segment the image based on different variations of yellow/orange for a "nice" image I get the following, without any false positives:

[![enter image description here](https://i.stack.imgur.com/FnKIM.png)](https://i.stack.imgur.com/FnKIM.png)

However, on images that are at a later point in the day, I receive the following:

[![enter image description here](https://i.stack.imgur.com/8TKDN.png)](https://i.stack.imgur.com/8TKDN.png)

I have played with the values for hours now, and cannot seem to find a happy medium that doesn't select both yellow and green in images. I was hoping the community could help provide some insight, since I've been scouring the web looking for examples of what I'm trying to accomplish for several days. I understand there are many examples of this being done in academic and scholarly paper/journals however I have no clue how to convert the complicated formulas they use into code. 

Here is the relevant python code:

```
# the below is pairs of yellow and red respectively
hsv_color_pairs = (
    (np.array([21, 100, 75]), np.array([25, 255, 255])),
    (np.array([1, 75, 75]), np.array([9, 225, 225]))
)
...
# this code is in a for loop and loops over the above HSV color ranges
mask = cv2.inRange(hsv, colors[0], colors[1])
out = cv2.bitwise_and(im, im, mask=mask)
blur = cv2.blur(out, (5, 5), 0)
imgray = cv2.cvtColor(blur, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(imgray, 0, 255, cv2.THRESH_OTSU)

heir, contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

```

so to sum things up, my question is: what are some tips/tricks I can use to segment the images for the specific colors of the orange/yellow warning signs with regard to shadows/exposure without picking up other colors such as green.

Thanks all!