5
$\begingroup$

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

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

enter image description here

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!

$\endgroup$
  • $\begingroup$ Google for "Colour Segmentation", "Colour Segmentation+ K means", "Python". "I have no clue how to convert the complicated formulas they use into code", thats everyones problems with over formalism of scientific papers! $\endgroup$ – MimSaad Apr 13 '17 at 16:40
  • $\begingroup$ I have not considered k-means before, however after some experimentation I don't think it will produce the results I need (unless I'm doing something wrong). k-means clusters the dominant colors in the image, which the colors I am looking for are not. Correct me if I am not quite understanding! $\endgroup$ – Tyler Roesler Apr 17 '17 at 22:27
  • $\begingroup$ take a look at this page : aishack.in/tutorials/dominant-color $\endgroup$ – MimSaad Apr 18 '17 at 10:43
1
$\begingroup$

To those looking at this in the future, I realized I was being silly and forgot how HSV worked! To pick up the yellow more so than the green I needed to heighten the threshold of the saturation value within the range!

As a side note, I also was able to "normalize" the colors of the image a bit more by converting to Lab color space and applying CLAHE (for localized histogram equalization) and as well on the saturation values within the HSV color space. This allowed me to get the signs in ideal lighting conditions almost 100% of the time (roughly speaking of course) with very little false positives, but didn't really alleviate my problems on images with a redish/orangeish hue as seen in the second example image. But, as was mentioned by harshkn, this approach is very simple so I suppose I can only ask for so much success! Thanks to all who replied with suggestions!

$\endgroup$
0
$\begingroup$

Your approach to solve this problem is a simple one. Color filtering can only get you that far. You can use color filtering after you have detected a traffic pole. So your computation pipeline must be preprocess_image => detect_traffic_pole => color_filtering => segmentation.

Edit - I mean to say detect_traffic_pole using feature other than color. If you use color, you will get lot of false positives. OR you can detect using color later use other feature(Eg-HOG) to verify it is traffic pole.

$\endgroup$
  • $\begingroup$ Could you possible expand on your ideas a bit? I am unsure how this is an answer to my question(s). $\endgroup$ – Tyler Roesler Apr 24 '17 at 20:57
  • $\begingroup$ updated my answer $\endgroup$ – harshkn Apr 25 '17 at 2:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.