I am trying to isolate objects of a certain color in an image. Looking at this image, you can see that I have extracted the hue channel, and have filtered these values so that the closer a pixel's hue is to a specified target hue, the brighter the pixel is (0 degrees difference = 255, and 180 degrees difference = 0). However, the results I am getting are not what I expected when comparing it against the source capture in the lower-right corner of the linked image. It seems that if picking green as a target hue, that certain pixels on the orange tape are closer to the target hue, than some pixels on the green tape.

So, I am wondering if I misunderstand what "hue" is, and if there is some other colorspace I should be leveraging, or if there are methods/algorithms out there to detect specific colors. The "banding" that is seen in the image makes me wonder if the camera hardware is doing some sort of compression that is affecting the output. I thought the black pixels might be n/a values in cases where the saturation was 0, however when I isolated the saturation channel to check, this was not the case.

  • 1
    \$\begingroup\$ I think there's something wrong with the implementation of extracting the hue channel. Hue can be unstable as saturation or brightness decrease, but there's no way you could have near 180 degree shifts in hue occur in lines like that in the green section without it being very obvious in the colour image. \$\endgroup\$
    – Matt Grum
    Jul 31, 2012 at 18:21
  • \$\begingroup\$ Hi Matt, you were correct. I went back through my code and found a large bug (albeit a single character typo) in the script running my hue extraction. Thanks for the tip! \$\endgroup\$
    – Dan
    Jul 31, 2012 at 19:02

1 Answer 1


I have to make this an answer rather than a comment due to the image upload. This is what I get as the hue channel of the included thumbnail:

thumbnail hue channel

Note that there hasn't been any math applied; the tones correspond to HSL hue values where 128 is cyan and 0 is red. (Because the values are angular, 255 is also red, nearly indistinguishable from 0 by eye, but not to the computer.) The whitish artifacts occur in dark areas with negligible saturation (blacks and deep shadows); the black bands above and below are because I included the white bands above and below the thumbnail and didn't notice they weren't part of the image until after I uploaded it. Going by the greyscale tones present, I can't see any way you could have gotten either the banding or the "false positives" in your result without there being a major problem with the hue channel extraction.

  • \$\begingroup\$ Hi Stan, you are correct that there was a bug in my hue channel extraction. I've fixed it and everything is working great now. Thanks for your time and help! \$\endgroup\$
    – Dan
    Jul 31, 2012 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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