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.

rgb2hsv

Convert RGB colormap to HSV colormap

Syntax

H = rgb2hsv(M)
hsv_image = rgb2hsv(rgb_image)

Description

H = rgb2hsv(M) converts an RGB colormap M to an HSV colormap H. Both colormaps are m-by-3 matrices. The elements of both colormaps are in the range 0 to 1.

The columns of the input matrix M represent intensities of red, green, and blue, respectively. The columns of the output matrix H represent hue, saturation, and value, respectively.

hsv_image = rgb2hsv(rgb_image) converts the RGB image to the equivalent HSV image. rgb_image is an m-by-n-by-3 image array whose three planes contain the red, green, and blue components for the image. HSV is returned as an m-by-n-by-3 image array whose three planes contain the hue, saturation, and value components for the image.

Class Support

If the input is an RGB image, it can be of class uint8, uint16, single, or double. The output image is single when the input is single. For all other input data types, the output image is double. If the input is a colormap, the input and output colormaps are both of class double.

More About

collapse all

Algorithms

Here are the conversion equations used in rgb2hsv:

v = max(max(r,g),b); 
h = zeros(size(v), 'like', r); 
s = (v - min(min(r,g),b)); 

z = ~s; 
s(z) = 1; 
k = (r == v); 
h(k) = (g(k) - b(k))./s(k); 
k = (g == v); 
h(k) = 2 + (b(k) - r(k))./s(k); 
k = (b == v); 
h(k) = 4 + (r(k) - g(k))./s(k); 
h = h/6; 
k = (h < 0); 
h(k) = h(k) + 1; 
h(z) = 0; 

tmp = s./v; 
tmp(z) = 0; 
k = (v~=0); 
s(k) = tmp(k); 
s(~v) = 0; 

Introduced before R2006a

Was this topic helpful?