4

I've heard that if you need to do a color segmentation on your software (create a binary image from a colored image by setting pixels to 1 if they meet certain threshold rules like R<100, G>100, 10< B < 123) it is better to first convert your image to HSV. Is this really true? And why?

bjou
  • 1,107
  • 1
  • 7
  • 19
JLagana
  • 1,224
  • 4
  • 14
  • 33
  • 2
    HSV is more meaningfully related to psychological perception of colour than RGB is - for example, if you want to segment on red, then in HSV all reds from lighest to darkest to least saturated to most saturated have the same hue, but in RGB if you filter by R > a certain amount you will catch bright oranges and miss dark reds, for example. – Patashu May 09 '13 at 23:22
  • If your conditions depend on the R, G and B values, why would you use HSV? – Blender May 09 '13 at 23:22
  • @Blender: That was just an example, if you use HSV then the segmentation relies on the H,S and V values for the threshold rules. – JLagana May 09 '13 at 23:26
  • This isn't a programming question.... – Jason May 09 '13 at 23:27
  • @Patashu: I agree with you, it is more meaningfully related. But from a performance point of view, why is that if I change to HSV before segmentation it will improve the overall quality of the segmentation? – JLagana May 09 '13 at 23:28
  • 1
    @Jason: If this is'nt a programming question then what is this? – JLagana May 09 '13 at 23:29
  • The conversion to HSV from RGB should be a bijection so it shouldn't matter, but I feel like this is off topic because it solicits an opinion, i.e. which is better. It can either be a psychological interpretation or scientific one depending on how you use the thresholded image, but either way not a programming question. I'd expect StackOverflow questions to be about algorithms, languages, bugs, compilation issues, code libraries, efficiency, etc. A question such as this would be more suited to scicomp.stackexchange.com – Jason May 09 '13 at 23:39
  • 1
    @Jason It is a bijection in the sense you can convert from one to the other, but in the context of computer vision programming it is not as various important computer vision algorithms handle the color spaces very differently. It is a very important question for any programming project that requires knowledge of color in an image. – Danny May 09 '13 at 23:49

1 Answers1

12

The big reason is that it separates color information (chroma) from intensity or lighting (luma). Because value is separated, you can construct a histogram or thresholding rules using only saturation and hue. This in theory will work regardless of lighting changes in the value channel. In practice it is just a nice improvement. Even by singling out only the hue you still have a very meaningful representation of the base color that will likely work much better than RGB. The end result is a more robust color thresholding over simpler parameters.

Hue is a continuous representation of color so that 0 and 360 are the same hue which gives you more flexibility with the buckets you use in a histogram. Geometrically you can picture the HSV color space as a cone or cylinder with H being the degree, saturation being the radius, and value being the height. See the HSV wikipedia page.

Danny
  • 2,221
  • 2
  • 18
  • 21