简体   繁体   English

MATLAB imread()无法读取旧图像?

[英]MATLAB imread() can't read old images?

So I ran into a weird problem with the MATLAB imread() function where it can't read old images (in this case, a bmp from 2002). 因此,我在使用MATLAB imread()函数时遇到了一个奇怪的问题,即该函数无法读取旧图像(在本例中为2002年的bmp)。 Basically when I pass the image as an argument to imread(), it recognises the image as a grayscale even though it is clearly RGB. 基本上,当我将图像作为参数传递给imread()时,即使图像显然是RGB,它也会将图像识别为灰度。

Image is part of a standard test set available to download from here . 图像是可从此处下载的标准测试集的一部分。 I am using the 'boy.bmp' image. 我正在使用'boy.bmp'图片。

% In Downloads folder    
I_dl = imread('boy.bmp');
whos %to show current variables

OUTPUT: 输出:

Name                    Size                 Bytes  Class     Attributes
I_dl                  512x768               393216  uint8               

The image size is actually around 390KB so it's not that only one channel is getting loaded into the workspace somehow. 图像大小实际上约为390KB,因此并不是只有一个通道以某种方式加载到工作区中。 Looks like it has to do with some older encoding system. 看起来它与某些较旧的编码系统有关。

I ran an imshow() to check the image and this was the result. 我运行了一个imshow()来检查图像,这就是结果。

TEMPORARY WORK-AROUND: I imported the image into GIMP, saved it as an xcf (GIMP's native format) and then exported it as a bmp. 临时工作:我将图像导入GIMP,将其保存为xcf(GIMP的本机格式),然后将其导出为bmp。 Then I did the imread() and then whos . 然后我做了imread()然后是whos It works. 有用。

Name                    Size                 Bytes  Class     Attributes
I                     512x768x3            1179648  uint8               

The file size expanded to 1.2MB too. 文件大小也扩展到了1.2MB。 Strange. 奇怪。

Any one else faced the same issue? 还有其他人遇到同样的问题吗?

Regards. 问候。

boy.bmp contains the indexed image . boy.bmp包含索引图像 You should load and use the colormap matrix: 您应该加载并使用颜色图矩阵:

[I_dl,cmap] = imread('boy.bmp');
imshow(I_dl,cmap);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM