Convert Between RGB and HSV Color Spaces - MATLAB & Simulink (2024)

Open Live Script

This example shows how to adjust the saturation of a color image by converting the image to the HSV color space. The example then displays the separate HSV color planes (hue, saturation, and value) of a synthetic image.

Convert RGB Image to HSV Image

Read an RGB image into the workspace. Display the image.

RGB = imread("llama.jpg");imshow(RGB)

Convert Between RGB and HSV Color Spaces- MATLAB & Simulink (1)

Convert the image to the HSV color space.

HSV = rgb2hsv(RGB);

Process the HSV image. This example increases the saturation of the image by multiplying the S channel by a scale factor.

[h,s,v] = imsplit(HSV);saturationFactor = 1.5;s_sat = s*saturationFactor;HSV_sat = cat(3,h,s_sat,v);

Convert the processed HSV image back to the RGB color space. Display the new RGB image. Colors in the processed image are more vibrant.

RGB_sat = hsv2rgb(HSV_sat);imshow(RGB_sat)

Convert Between RGB and HSV Color Spaces- MATLAB & Simulink (2)

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,BackgroundColor="w");

Convert Between RGB and HSV Color Spaces- MATLAB & Simulink (3)

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.

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Convert Between RGB and HSV Color Spaces- MATLAB & Simulink (4)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

Europe

Asia Pacific

Contact your local office

Convert Between RGB and HSV Color Spaces
- MATLAB & Simulink (2024)
Top Articles
Latest Posts
Article information

Author: Fr. Dewey Fisher

Last Updated:

Views: 6008

Rating: 4.1 / 5 (42 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Fr. Dewey Fisher

Birthday: 1993-03-26

Address: 917 Hyun Views, Rogahnmouth, KY 91013-8827

Phone: +5938540192553

Job: Administration Developer

Hobby: Embroidery, Horseback riding, Juggling, Urban exploration, Skiing, Cycling, Handball

Introduction: My name is Fr. Dewey Fisher, I am a powerful, open, faithful, combative, spotless, faithful, fair person who loves writing and wants to share my knowledge and understanding with you.