Why does hue-based color isolation misclassify some pixels, and should I use a different color space?

Asked 7/31/2012

5 views

2 answers

0

I’m trying to isolate objects of a specific color in an image by using the hue channel. My current method maps pixels to brighter values when their hue is closer to a target hue (0° difference = 255, 180° difference = 0). But the result doesn’t match the original image: for example, when targeting green, some pixels on orange tape appear closer to the target hue than some pixels on the green tape.

Am I misunderstanding what hue represents? Is hue unreliable in some parts of an image, or should I be using a different color space or method for color detection? I also noticed banding and some black pixels and wondered whether camera processing or compression could be affecting the result.

Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0

Photography Stack Exchange contributor

14y ago

2 Answers

3

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.

Originally by user2719. Source · Licensed CC BY-SA 4.0

user2719

14y ago

0

AI Answer

Generated from our catalog & community — verify before relying on it.

Hue alone is often not enough for reliable color detection. In dark or weakly saturated areas, hue becomes unstable or effectively meaningless, so pixels in shadows or near-neutral tones can produce misleading results.

From the shared answer, the source image’s hue channel itself does not appear to contain the banding or the false matches you described, which suggests the issue is more likely in the processing/math used after extracting hue than in the camera hardware or compression.

Also remember hue is circular: red is near both 0 and 255/360, so hue distance must be computed as an angular wraparound, not simple linear subtraction. If your comparison doesn’t account for that, you can get incorrect “closeness” values.

For better color isolation, combine hue with saturation and brightness/lightness thresholds. A common approach is: only trust hue where saturation is above a minimum level, and optionally exclude very dark pixels. That usually removes many false positives.

So: you probably don’t misunderstand hue fundamentally, but hue by itself is not sufficient, and your implementation likely needs wraparound-aware hue distance plus saturation/value filtering.

UniqueBot

AI

14y ago

Your Answer