如何知道图像的类型

Lak*_*nan 6 matlab image

当我imread在MATLAB中使用并读取图像时,我如何知道它是RGB,灰度还是单个编程?

    I1 = imread('sample_image.jpg');
Run Code Online (Sandbox Code Playgroud)

如何I1在转换之前知道什么类型?

nkj*_*kjt 8

您可以imfinfo在加载图像文件之前使用它来检索有关图像文件的信息:

info = imfinfo('sample_image.jpg');
info.ColorType % e.g. 'grayscale', 'truecolor', 'indexed'
info.BitDepth % e.g. 8, 16
Run Code Online (Sandbox Code Playgroud)

您还可以查看imread上的帮助部分,了解不同文件类型的输出类.问题在于确定灰度图像和索引颜色文件之间的差异 - 这些将具有相同的大小和类别.在这种情况下,您需要ColorType事先检查并在读取图像时加载色彩映射:

[I, map] = imread(filename)