rgb2hsv
Convert RGB colors to HSV
Description
Examples
Get a down-sampled version of the prism colormap.
rgb = prism(6)
rgb = 6×3
    1.0000         0         0
    1.0000    0.5000         0
    1.0000    1.0000         0
         0    1.0000         0
         0         0    1.0000
    0.6667         0    1.0000
Convert the RGB values in the colormap to HSV.
hsv = rgb2hsv(rgb)
hsv = 6×3
         0    1.0000    1.0000
    0.0833    1.0000    1.0000
    0.1667    1.0000    1.0000
    0.3333    1.0000    1.0000
    0.6667    1.0000    1.0000
    0.7778    1.0000    1.0000
Create a 2-by-2 truecolor image.
rgb(:,:,1) = [1 1; 0 .5]; rgb(:,:,2) = [0 1; 0 .5]; rgb(:,:,3) = [0 0; 1 .5]; image(rgb);

Convert the image to an HSV array.
hsv = rgb2hsv(rgb)
hsv = 
hsv(:,:,1) =
         0    0.1667
    0.6667         0
hsv(:,:,2) =
     1     1
     1     0
hsv(:,:,3) =
    1.0000    1.0000
    1.0000    0.5000
Input Arguments
RGB image to convert, specified as an
                            m-by-n-by-3 numeric array. The
                        third dimension of RGB defines the red, green, and blue
                        intensity of each pixel, respectively.
The rgb2hsv function expects truecolor images of data
                        type double and single to have values
                        in the range [0, 1].
Data Types: single | double | uint8 | uint16
RGB colormap, specified as a c-by-3 numeric matrix with
                        values in the range [0, 1]. Each row of rgbmap is a
                        three-element RGB triplet that specifies the red, green, and blue components
                        of a single color of the colormap.
Data Types: double
Output Arguments
HSV image, returned as an
                        m-by-n-by-3 numeric array with values
                        in the range [0, 1]. The third dimension of HSV defines
                        the hue, saturation, and value for each pixel, respectively, as described in
                        the table.
| Attribute | Description | 
|---|---|
| Hue | Value from 0to1that corresponds to the color’s
                                            position on a color wheel. As hue increases from0to1, the
                                            color transitions from red to orange, yellow, green,
                                            cyan, blue, magenta, and finally back to red. | 
| Saturation | Amount of hue or departure from neutral. 0indicates a neutral shade,
                                            whereas1indicates maximum
                                            saturation. | 
| Value | Maximum value among the red, green, and blue components of a specific color. | 
The data type of HSV depends on the data type of
                            RGB: 
- If - RGBis of data type- single, then- HSVis of data type- single.
- Otherwise, - HSVis of data type- double.
Data Types: double | single
HSV colormap, returned as a c-by-3 numeric matrix with
                        values in the range [0, 1]. Each row of hsvmap is a
                        three-element HSV triplet that specifies the hue, saturation, and value
                        components of a single color of the colormap. 
The data type of hsvmap depends on the data type of
                            rgbmap: 
- If - rgbmapis of data type- single, then- hsvmapis of data type- single.
- Otherwise, - hsvmapis of data type- double.
Data Types: single | double
References
[1] Smith, A. R. “Color Gamut Transform Pairs”. SIGGRAPH 78 Conference Proceedings. 1978, pp. 12–19.
Extended Capabilities
C/C++ Code Generation
 Generate C and C++ code using MATLAB® Coder™.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
The rgb2hsv function
    fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced before R2006a
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.
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
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)