简体   繁体   English

如何在Matlab中显示RGB图像,其中每个通道都是单独的矩阵?

[英]How to display RGB images in Matlab, where each channel is separate matrix?

I was given a dataset with human faces in Matlab format, but I don't know how to display the images, after I have imported the dataset in Matlab. 给了我一个Matlab格式的人脸数据集,但是将数据集导入Matlab后,我不知道如何显示图像。

The size of the matrix is 60x60x3x1000, which means, the images are of dimensions 60x60, there are 3 channels per image RGB, and there are 1000 such images. 矩阵的大小为60x60x3x1000,这意味着图像的尺寸为60x60,每个图像RGB有3个通道,并且有1000个此类图像。

I can't figure out how to do basic operations like, display the i-th face in color. 我不知道如何进行基本操作,例如以彩色显示第i张脸。

Thanks 谢谢

Have you tried image(1:60, 1:60, Images(:, :, :, i)) ? 您是否尝试过image(1:60, 1:60, Images(:, :, :, i))吗?

To get an individual channel you can do: 要获得单个频道,您可以执行以下操作:

colormap(gray)
image(Images(:,:,1,i))

or 要么

colormap(gray)
image(Images(:,:,2,i))

or 要么

colormap(gray)
image(Images(:,:,3,i))

That should separate the channels for you and scale individual color components to the correct saturation levels. 那应该为您分开通道,并将各个颜色分量缩放到正确的饱和度水平。

Also, if you are getting an error about it being out of range try: 另外,如果遇到超出范围的错误,请尝试:

imagesc(1:60, 1:60, Images(:, :, :, i)) 

That said it is hard for me to believe your professor or colleague didn't give you RGB data in the standard [0,255] format. 那就是说我很难相信您的教授或同事没有给您提供标准[0,255]格式的RGB数据。 If you do that, though, imagesc will be useless in comparing the color channels side by side. 但是,如果这样做, imagesc在并排比较颜色通道时将毫无用处。

It could also be helpful to see what some of the values in each color matrix look like. 看看每个颜色矩阵中的某些值是什么样子也可能会有帮助。 We could see that if you gave me the output of: 我们可以看到,如果您给我输出以下内容:

min(Images(:, :, 1, 1))
max(Images(:, :, 1, 1))

If in fact they are some kind of float, I can show you how to scale it to the standard integer RGB representation. 如果实际上它们是某种浮点数,我可以向您展示如何将其缩放为标准整数RGB表示形式。

It appears as if the data is given in the range [0..255] but of type double (rather than uint8 ). 看起来好像在[0..255]范围内给出数据,但类型为double(而不是uint8 )。

So, to get the k-th image you need 因此,要获得第k个图像,您需要

Im_k = uint8( squeeze( Images(:,:,:,k) ) );

or, if you want to use double precision floating points 或者,如果您想使用双精度浮点

Im_k = squeeze( Images(:,:,:,k) ) / 255;

(I'm not 100% sure you need to use squeeze in this case). (在这种情况下,我不是100%确定您需要使用squeeze )。

Display the image 显示图像

figure('Name', 'Showing k-th face');
imshow( Im_k );

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

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