Main Content

图像类型转换

在不同的图像类型(如 RGB(真彩色)、二值图像、灰度图像和索引图像)之间进行转换,并更改图像的数据类型

Image Processing Toolbox™ 支持二值、索引、灰度和真彩色图像类型。在每种图像类型中,像素以不同格式存储。例如,真彩色图像将像素表示为红、绿和蓝值的三元组,而灰度图像将一个像素表示为单个强度值。

不同图像类型的像素值可以以浮点、有符号和无符号整数或逻辑值数据类型存储。工具箱函数使您能够在图像类型和数据类型之间进行转换。

函数

全部展开

cmap2gray将 RGB 颜色图转换为灰度颜色图 (自 R2020b 起)
gray2ind将灰度或二值图像转换为索引图像
im2gray将 RGB 图像转换为灰度图像 (自 R2020b 起)
ind2gray将索引图像转换为灰度图像
mat2gray将矩阵转换为灰度图像
rgb2gray将 RGB 图像或颜色图转换为灰度图
rgb2lightnessConvert RGB color values to lightness values
rgb2ind将 RGB 图像转换为索引图像
ind2rgb将索引图像转换为 RGB 图像
label2rgbConvert label matrix into RGB image
demosaicConvert Bayer pattern encoded image to truecolor image
imsplitSplit multichannel image into its individual channels
imbinarize通过阈值化将二维灰度图像或三维体二值化
adaptthresh使用局部一阶统计量的自适应图像阈值
otsuthresh使用 Otsu 方法的全局直方图阈值
graythresh使用 Otsu 方法计算全局图像阈值
imquantizeQuantize image using specified quantization levels and output values
multithreshMultilevel image thresholds using Otsu’s method
graysliceConvert grayscale image to indexed image using multilevel thresholding
im2double将图像转换为双精度值
im2int16将图像转换为 16 位有符号整数
im2single将图像转换为单精度
im2uint16将图像转换为 16 位无符号整数
im2uint8将图像转换为 8 位无符号整数

主题

  • Image Types in the Toolbox

    Image types determine how MATLAB® interprets data matrix elements as pixel intensity values. The toolbox supports many image types including binary, grayscale, truecolor, multispectral, and label images.

  • Convert Between Image Types

    Certain image processing operations support only a subset of the image types. You can convert images between the image types to suit the operation.

  • Convert Image Data Between Data Types

    You can convert image data between data types using functions that automatically rescale and offset the original data.