Main Content

ind2gray

Convert indexed image to grayscale image

Description

example

I= ind2gray(X,cmap)converts the indexed imageXwith colormapcmapto a grayscale image,I. Theind2grayfunction removes the hue and saturation information from the input image while retaining the luminance.

Examples

collapse all

Load an indexed image into the workspace.

[X, map] = imread('trees.tif');

Convert the image to grayscale usingind2gray.

I = ind2gray(X,map);

Display the indexed image and the converted grayscale image.

imshow(X,map) title('Indexed Image')

Figure contains an axes object. The axes object with title Indexed Image contains an object of type image.

figure imshow(I) title('Converted Grayscale Image')

Figure contains an axes object. The axes object with title Converted Grayscale Image contains an object of type image.

Input Arguments

collapse all

Indexed image, specified as a numeric array of any size and dimensionality.

Data Types:single|double|uint8|uint16

Colormap associated with indexed imageX, specified as ac-by-3 numeric matrix with values in the range [0, 1]. Each row 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

collapse all

Grayscale image, specified as a numeric array.Ihas the same size, dimensionality and class asX.

Algorithms

ind2grayconverts the colormap to NTSC coordinates usingrgb2ntsc, and sets the hue and saturation components (IandQ) to zero, creating a gray colormap.ind2graythen replaces the indices in the imageXwith the corresponding grayscale intensity values in the gray colormap.

Extended Capabilities

版本历史

Introduced before R2006a