table of Contents
ind2gray converts indexed image to grayscale image
Convert indexed image to grayscale
ind2gray converts indexed image to grayscale image
syntax
I = ind2gray(X,cmap)
description
I = ind2gray(X,cmap)
ConvertX
an indexed image with a color map tocmap
a grayscale imageI
. Thisind2gray
function removes hue and saturation information from the input image while maintaining brightness.
example
Convert indexed image to grayscale
Load the indexed image into the workspace.
[X,map] = imread('trees.tif');
Use to convert the image to grayscale ind2gray
.
I = ind2gray(X,map);
Display the index image and the converted grayscale image.
imshow(X,map)
title('Indexed Image')
figure
imshow(I)
title('Converted Grayscale Image')
Input parameters
X
—Index image
number array
Index image, specified as a numeric array of any size and dimensions.
Data type:single
| double
| uint8
|uint16
cmap
-Color map-c
by-3 digital array
The color map X associated with the indexed image is specified as c
an array of -by-3 numbers, where c
is the number of colors.
Data type: double
Output parameters
I
—Gray image
digital array
Grayscale image, specified as an array of numbers. I
Has the same size, size and category X.
Algorithm
ind2gray
Use to convert the color map to NTSC coordinates rgb2ntsc, and set the hue and saturation components ( I and Q ) to zero to create a gray color map. ind2gray
Then replace the index in the image with the corresponding gray intensity value in the X gray color map.