Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

hsv2rgb

Convert HSV colors to RGB

Syntax

rgb = hsv2rgb(hsv)

Description

example

rgb = hsv2rgb(hsv) converts hue, saturation, and value (HSV) coordinates to the appropriate red, green, and blue (RGB) values. Array hsv can be a three-column array or an m-by-n-by-3 array. Output array rgb is the same size and numeric type as hsv.

Examples

collapse all

Create a three-column HSV matrix that specifies five shades of blue. In this case, hue and value are constant, while saturation varies between 1.0 and 0.0.

hsv = [.6 1 1; .6 .7 1; .6 .5 1; .6 .3 1; .6 0 1]; 

Convert the HSV matrix to a colormap by calling hsv2rgb. Then use that colormap in a surface plot.

rgb = hsv2rgb(hsv);
surf(peaks);
colormap(rgb);
colorbar

Create a 2-by2-by-3 HSV array that specifies four shades of blue.

hsv(:,:,1) = ones(2,2)*.6;
hsv(:,:,2) = [1 .7; .3 0];
hsv(:,:,3) = ones(2,2);

Convert the HSV array to a truecolor image using hsv2rgb. Then display the image.

rgb = hsv2rgb(hsv);
image(rgb);

Input Arguments

collapse all

HSV values to convert, specified as a p-by-3 array or an m-by-n-by-3 image array. The values are of type double or single and in the range [0, 1]. The attributes (hue, saturation, and value) are described in the following table.

AttributeDescription Location in hsv Array
HueValue from 0 to 1 that corresponds to the color’s position on a color wheel. As hue increases from 0 to 1, the color transitions from red to orange, yellow, green, cyan, blue, magenta, and finally back to red.
  • hsv(:,1) when hsv is p-by-3

  • hsv(:,:,1) when hsv is m-by-n-by-3

SaturationAmount of hue or departure from neutral. 0 indicates a neutral shade, whereas 1 indicates maximum saturation.
  • hsv(:,2) when hsv is p-by-3

  • hsv(:,:,2) when hsv is m-by-n-by-3

Value

Maximum value among the red, green, and blue components of a specific color.

  • hsv(:,3) when hsv is p-by-3

  • hsv(:,:,3) when hsv is m-by-n-by-3

Data Types: double | single

Output Arguments

collapse all

RGB values, returned as an array that is the same size and numeric type as hsv: a p-by-3 array or an m-by-n-by-3 image array of type double or single.

When rgb is a p-by-3 array, then each row contains an RGB triplet. An RGB triplet is a three-element row vector whose values are the red, green, and blue components of a color, respectively.

When rgb is an m-by-n-by-3 image array, the third dimension specifies the red, green, or blue intensity at pixel (i,j):

  • rgb(i,j,1) specifies the red intensity.

  • rgb(i,j,2) specifies the green intensity.

  • rgb(i,j,3) specifies the blue intensity.

Data Types: double | single

References

[1] Smith, A. R. “Color Gamut Transform Pairs”. SIGGRAPH 78 Conference Proceedings. 1978, pp. 12–19.

See Also

Introduced before R2006a

Was this topic helpful?