Matlab-indexed image into true color image

Convert indexed images into true color images

[X,map] = imread('corn.tif');
//%索引图像X是uint8类型的415×312 数组.颜色图 cmap 是 double 类型的 256×3 矩阵,因此索引图像中有 256 种颜色。
RGB = ind2rgb(X,map);
//%将索引图像转换为 RGB 图像。结果为一个 double 类型的 415×312×3 数组。
disp(['Range of RGB image is [',num2str(min(RGB(:))),', ',num2str(max(RGB(:))),'].']);
//%检查 RGB 图像的值是否在 [0, 1] 范围内。
imshow(RGB);

Insert picture description here

Detailed explanation of ind2rgb() function

grammar

RGB = ind2rgb(X,map)

RGB = ind2rgb(X,map)Convert the index image X and the corresponding color map mapto RGB (true color) format.

Input parameters

X--索引图像 m×n整数矩阵

  • If X is specified as an array of integer data type, the value 0 corresponds to the first color in the color map. For a color map containing c colors, the value of the image X will be cropped to the range [0, c-1].
  • If X is specified as an array of single or double data type, the value 1 corresponds to the first color in the color map. For a color map containing c colors, the value of the image X will be clipped to the range [1, c].

Data type : single | double | uint8 | uint16

map--颜色图 c×3 的矩阵

The color map associated with the index image X, specified as a c×3 matrix of values ​​in the range [0, 1]. Each row of the map is a three-element RGB, which specifies the red, green, and blue components of a single color of the color map.

Data type : double

Output parameters

RGB--RGB图像 m×n×3 数值数组
RGB image, returned as an m×n×3 numeric array consisting of values ​​in the range [0, 1].
Data type : double

Guess you like

Origin blog.csdn.net/qq_45465526/article/details/104100617