Main Content

ind2gray

将索引图像转换为灰度图像

说明

I = ind2gray(X,cmap) 将使用颜色图 cmap 的索引图像 X 转换为灰度图像 Iind2gray 函数从输入图像中删除色调及饱和度信息,同时保持亮度。

示例

示例

全部折叠

将索引图像加载到工作区。

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

使用 ind2gray 将图像转换为灰度图像。

I = ind2gray(X,map);

显示索引图像和转换后的灰度图像。

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

Figure contains an axes object. The hidden 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 hidden axes object with title Converted Grayscale Image contains an object of type image.

输入参数

全部折叠

索引图像,指定为任意大小和维度的数值数组。

数据类型: single | double | uint8 | uint16

与索引图像 X 相关联的颜色图,指定为由范围 [0, 1] 内的值组成的 c×3 数值矩阵。每行是一个三元素 RGB 三元组,指定颜色图的单个颜色的红、绿和蓝分量。

数据类型: double

输出参量

全部折叠

灰度图像,指定为数值数组。IX 具有相同的大小、维度和类。

算法

ind2gray 使用 rgb2ntsc 将颜色图转换为 NTSC 坐标,并将色调及饱和度分量(IQ)设置为零,从而创建一个灰度颜色图。然后,ind2gray 将图像 X 中的索引替换为灰度颜色图中对应的灰度强度值。

扩展功能

版本历史记录

在 R2006a 之前推出

全部展开