rgb2hsv
Converts colors from red-green-blue to hue-saturation-value.
Category: Graphics > Formatting and Annotation
Syntax
hsv = rgb2hsv(rgb)
Converts an m-by-3 colormap or an image of size m-by-n-by-3 from RGB to HSV.
Description
The value is the largest of the three channels and the saturation is the spread between largest and smallest, relative to the value. The hue is the position on the color wheel as a fraction: 0 for red, 1/3 for green and 2/3 for blue. For a gray color, where all channels are equal, saturation and hue are 0.
The conversion is useful to change brightness or saturation of a picture without shifting its colors. The inverse is hsv2rgb.
Input arguments
rgb- Colormap or image with values between 0 and 1 in the last dimension. Integer images are converted to double first.
Output arguments
hsv- Array of the same size with hue, saturation and value in the range 0 to 1.
Example
Red, cyan and a gray
rgb2hsv([1 0 0; 0 1 1; 0.5 0.5 0.5])
Output
ans = 3×3
0 1.0000 1.0000
0.5000 1.0000 1.0000
0 0 0.5000