Thursday, August 24, 2023

OpenCV basics continued...HSV Color Space and Channels

In addition to the BGR color space, an image can also be represented by HSV (Hue, Saturation, Value) color space, also known as HSB (Hue, Saturation, Brightness), which is a cylindrical color space that describes colors based on three attributes: hue, saturation, and value/brightness, as shown in Figure below. The three attributes are also represented in channels. 

In the HSV color space, colors are represented as a point in a cylindrical coordinate system. The hue is represented by the angle on the horizontal axis, the saturation is represented by the radius or distance from the center, and the value/brightness is represented by the vertical axis.

The HSV is often used in graphics software for color selection and manipulation because it allows users to easily adjust the hue, saturation, and value/brightness of color separately. For example, changing the hue will change the color family, while changing the saturation or brightness will alter the intensity or lightness/darkness of the color.


Hue represents the color portion of the image, which is described as an angle on a color wheel ranging from 0 to 359 degrees. Figure below shows the color wheel, different colors are distributed around a circle with red at 0 degree, green at 120 degrees, and blue at 240 degrees. Hue value at different angles represent different colors.

Normally the hue value is from 0 to 359 representing an angle of the circle, however in OpenCV the values of hue are different, since the values are stored in an 8-bit datatype with the range of [0, 255], which can not store the entire hue value of [0, 359]. OpenCV is using a trick to resolve it, the hue value is divided by 2 and stored in the 8-bit datatype. Therefore, the hue in OpenCV is [0, 179].


The below table shows the Hue value at different angles and the corresponding color name and code:



Saturation represents the intensity or purity of the color, the value is defined from 0 to 100 percent, where 0 is gray and 100 percent is the pure color. As the saturation increases the color appears to be purer, a highly saturated image is more vivid and colorful. As the saturation decreases the color appears to be faded out, a less saturated image appears towards a grayscale one.

In OpenCV, however, its value range is extended to [0, 255] instead of [0, 100]. Value/Brightness represents the overall brightness of the color, the value is defined from 0 to 100 percent, where 0 is black and 100 is the brightest level of the color.

Similar to saturation, in OpenCV the range for Value/Brightness is [0, 255], instead of [0, 100]. Same as BGR channels, the HSV is also separated into three channels as well, each in grayscale. Figure below illustrates how the Hue, Saturation and Value/Brightness channels can compose a color image.


In summary, the HSV color space is a cylindrical color model that describes colors based on their hue, saturation, and value/brightness. It’s widely used in various applications that involve color selection, manipulation, and analysis.

Share:

0 comments:

Post a Comment