This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Convert from HSV to RGB Color Space

The HSV color space (Hue, Saturation, Value) is often used by people who are selecting colors (e.g., of paints or inks) from a color wheel or palette, because it corresponds better to how people experience color than the RGB color space does. The functions rgb2hsv and hsv2rgb convert images between the RGB and HSV color spaces.

Note

MATLAB® and the Image Processing Toolbox™ software do not support the HSI color space (Hue, Saturation, Intensity). However, if you want to work with color data in terms of hue, saturation, and intensity, the HSV color space is very similar. Another option is to use the LCH color space (Luminosity, Chroma, and Hue), which is a polar transformation of the CIE L*a*b* color space — see Device-Independent Color Spaces.

As hue varies from 0 to 1.0, the corresponding colors vary from red through yellow, green, cyan, blue, magenta, and back to red, so that there are actually red values both at 0 and 1.0. As saturation varies from 0 to 1.0, the corresponding colors (hues) vary from unsaturated (shades of gray) to fully saturated (no white component). As value, or brightness, varies from 0 to 1.0, the corresponding colors become increasingly brighter.

The following figure illustrates the HSV color space.

Illustration of the HSV Color Space

Convert RGB image to HSV and Explore HSV Color Space

This example shows how to convert an RGB image to the HSV color space using the rgb2hsv function. The example then displays the separate HSV color planes (hue, saturation, and value) of a synthetic image.

Convert an RGB Image into an HSV Image

Read an RGB image into the workspace.

RGB = imread('peppers.png');

Convert it to the HSV color space.

HSV = rgb2hsv(RGB);

Closer Look at the HSV Color Space

For closer inspection of the HSV color space, create a synthetic RGB image.

RGB=reshape(ones(64,1)*reshape(jet(64),1,192),[64,64,3]);

Convert the synthetic RGB image to the HSV colorspace.

HSV=rgb2hsv(RGB);

Split the HSV version of the synthetic image into its component planes: hue, saturation, and value.

[h s v] = imsplit(HSV);

Display the individual HSV color planes with the original image.

montage({h, s, v, RGB}, 'BorderSize', 10);

As the hue plane image in the preceding figure illustrates, hue values make a linear transition from high to low. If you compare the hue plane image against the original image, you can see that shades of deep blue have the highest values, and shades of deep red have the lowest values. (As stated previously, there are values of red on both ends of the hue scale. To avoid confusion, the sample image uses only the red values from the beginning of the hue range.)

Saturation can be thought of as the purity of a color. As the saturation plane image shows, the colors with the highest saturation have the highest values and are represented as white. In the center of the saturation image, notice the various shades of gray. These correspond to a mixture of colors; the cyans, greens, and yellow shades are mixtures of true colors. Value is roughly equivalent to brightness, and you will notice that the brightest areas of the value plane correspond to the brightest colors in the original image.