32.5 Color Conversion

Octave supports conversion from the RGB color system to the HSV color system and vice versa. It is also possible to convert from a color RGB image to a grayscale image.

: hsv_map = rgb2hsv (rgb_map)
: hsv_img = rgb2hsv (rgb_img)

Transform a colormap or image from RGB to HSV color space.

A color in the RGB space consists of red, green, and blue intensities.

A color in HSV space is represented by hue, saturation and value (brightness) levels in a cylindrical coordinate system. Hue is the azimuth and describes the dominant color. Saturation is the radial distance and gives the amount of hue mixed into the color. Value is the height and is the amount of light in the color.

Output class and size will be the same as input.

See also: hsv2rgb, rgb2ind, rgb2gray.

: rgb_map = hsv2rgb (hsv_map)
: rgb_img = hsv2rgb (hsv_img)

Transform a colormap or image from HSV to RGB color space.

A color in HSV space is represented by hue, saturation and value (brightness) levels in a cylindrical coordinate system. Hue is the azimuth and describes the dominant color. Saturation is the radial distance and gives the amount of hue mixed into the color. Value is the height and is the amount of light in the color.

The input can be both a colormap or RGB image. In the case of floating point input, values are expected to be on the [0 1] range. In the case of hue (azimuth), since the value corresponds to an angle, mod (h, 1) is used.

>> hsv2rgb ([0.5 1 1])
⇒ ans = 0 1 1

>> hsv2rgb ([2.5 1 1])
⇒ ans = 0 1 1

>> hsv2rgb ([3.5 1 1])
⇒ ans = 0 1 1

Output class and size will be the same as input.

See also: rgb2hsv, ind2rgb.

: I = rgb2gray (rgb_img)
: gray_map = rgb2gray (rgb_map)

Transform an image or colormap from red-green-blue (RGB) color space to a grayscale intensity image.

The input may be of class uint8, int8, uint16, int16, single, or double. The output is of the same class as the input.

Implementation Note: The grayscale intensity is calculated as

I = 0.298936*R + 0.587043*G + 0.114021*B

which corresponds to the luminance channel when RGB is translated to YIQ as documented in https://en.wikipedia.org/wiki/YIQ.

See also: rgb2hsv, rgb2ind.

© 1996–2020 John W. Eaton
Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions.
https://octave.org/doc/v6.3.0/Color-Conversion.html