I see the HSV colour space used all over the place: for tracking, human detection, etc... I'm wondering, why? What is it about this colour space that makes it better than using RGB?
The simple answer is that unlike RGB, HSV separates luma, or the image intensity, from chroma or the color information. This is very useful in many applications. For example, if you want to do histogram equalization of a color image, you probably want to do that only on the intensity component, and leave the color components alone. Otherwise you will get very strange colors.
In computer vision you often want to separate color components from intensity for various reasons, such as robustness to lighting changes, or removing shadows.
Note, however, that HSV is one of many color spaces that separate color from intensity (See YCbCr, Lab, etc.). HSV is often used simply because the code for converting between RGB and HSV is widely available and can also be easily implemented. For example, the Image Processing Toolbox for MATLAB includes functions
The color information is usually much more noisy than the HSV information.
Let me give you an example: Me and some friends were involved in a project dealing with the recognition of traffic signs in real scene videos (noise, shadows and sometimes occlusion present). It was a part of a bigger project, so that allowed us time to try out different approaches to this particular problem (and re-use older approaches). I did not try color-based approach myself, but I remember an interesting information: _The dominant RGB component in a STOP sign was often not red! (mostly due to shadows)
You can usually get better information from a HSV colorspace. Let me try and give a personal experience example again: Try imagining you have an image of a single-color plane with a shadow on it. In RGB colorspace, the shadow part will most likely have very different characteristics than the part without shadows. In HSV colorspace, the hue component of both patches is more likely to be similar: the shadow will primarily influence the value, or maybe satuation component, while the hue, indicating the primary "color" (without it's brightness and diluted-ness by white/black) should not change so much.
If this explanations do not sound intuitive to you, I suggest:
- try and better understand components used to represent a color in HSV colorspace, and renew you knowledge of RGB
try and see the reasons why these kinds of color representation were developed: it is always in some way, based on some view of human interpretation of color
e.g. children do not actually like highly colored == valued objects, they prefer highly satuated objects, objects in which the color is intense and non-diluted
after you get this and develop some intuition, you should play with images: try decomposing various images in their R-G-B and H-S-V components
Your goal would be to see and understand a difference in these decompositions for images that contain shadows, strong illumination, light reflection.
if you have a particular type of images you like to play with, try decomposing them: who knows, maybe RGB really is more suited for your needs than HSV :)
Using only the Hue component makes the algorithm less sensitive (if not invariant) to lighting variations.
Another popular option is LAB color space, where the AB channels represent the color and euclidean distances in AB space better match the human perception of color. Again, ignoring the L channel (Luminance) makes the algorithm more robust to lighting differences.
The best answer I can figure is: RGB has to do with "implementation details" regarding the way RGB displays color, and HSV has to do with the "actual color" components. Another way to say this would be RGB is the way computers treats color, and HSV try to capture the components of the way we humans perceive color.
Color is a perception based on electromagnetic waves. Natural properties of these waves are,for example intensity and frequency. If we sweep the frequency of a lightwave from infra-red to ultra-violet, we would visually perceive a color variation along the rainbow colors. Rainbow colors could be considered "pure colors" because they are represented by single-frequency waves.
Now the human eye can only respond, or "resonate" to three main light frequencies, not surprisingly red, green and blue. The fact is that this response is non-linear, so the retina can distinguish a given pure color (and implicitly its "frequency") by the combined response of the three color components.
The RGB color space exists as such only to mimic the internal workings of our retina, so that a vast majority of colors can be represented on computer displays by means of a convenient (from a computer point of view) 24 bits-per-pixel color coding. The RGB color space has no intrinsic relation to the natural color properties, neither to human interpretation of color.
For example, any arithmetical operation performed channel-wise in RGB space (for example, generation of color gradients) gives very crude or even plainly "wrong" results. That's why it is advised to create colormaps by converting the color stops from RGB to other color spaces (HLS, Lab, etc.), performing the interpolations, then converting the interpolated values back to RGB.
Hope this helps!
HSV stands for Hue-Saturation-Value. It is actually a type of color plane representation (like RGB, YCbCr etc.).
It is a device independent color representation format: The HSV color representation is useful to detect specific color types, e.g.: skin color, fire color etc.
Matlab function to convert an RGB image to HSV plane is
There is nothing I know of that is especially better with HSV as compared to YUV or LAB that would make it better for the feature extraction and illumination invariance or visualization. I guess HSV is the more commonly used one because of convention and continuity: its easier to compare results and communicate with each other if you both use the same colorspace.
With that said, HSV (as opposed to RGB) is used in computer vision for 2 reasons I know of:
- Visualization. Whenever you have directional information densely over an image, then HSV is a good color space for visualization. Instead of plotting little vectors over an image(they will clutter everything), you can plot color with HSV, by putting the directional vector mapped to the H (vector angle) and S(vector magnitude). This leaves the Value component, which can be set in any number of ways depending on what you want to achieve. See below example from the middlebury optical flow dataset. HSV is used to display directions densely.
- Feature extraction and illumination invariance, as explained in the other answers.
As others mentioned, it is beneficial to separate the luma from the chroma. The luma varies greatly in the scene based on the amount of light falling on the object. Chroma, on the other hand, correlates better with the object's intrinsic properties, and for properly white-balanced images is more-or-less invariant.
However, I would like to add that HSV, HSL, or in fact any color space with polar parametrization of the chroma plane, are bad choices for that purpose. That is because they introduce a singularity on the line of grays (which hue is gray?), making them very sensitive to noise and white-balance. Additionally comparing between two colors in a polar coordinate system isn't as straight forward. Also note that neither the value in HSV nor lightness in HSL correspond to the human perceived lightness or any other physical measure of energy.
There are plenty of linear color spaces that give the same luma-chroma separation while preserving linearity (YCbCr, YUV) or model human vision properly (LUV, LAB). With those you can compare two colors using a Euclidean L2 norm on their chromaticities, resulting in a more robust algorithm overall.
Why HSV/HSL are used so often then? Hard to give an objective answer. From my experience it's mostly due to ignorance and the availability of RGB->HSV conversion routines. Had to work with code whose authors didn't understand gamma-correction, let alone different color-spaces. Seen code that converted RGB to HSV then segmented the image based on the hue, disregarding the fact that it's a modular quantity. I think we can agree that those weren't conscious decisions backed by any reason.