简体   繁体   中英

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.

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.

I can't figure out how to do basic operations like, display the i-th face in color.

Thanks

Have you tried 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. If you do that, though, imagesc will be useless in comparing the color channels side by side.

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.

It appears as if the data is given in the range [0..255] but of type double (rather than uint8 ).

So, to get the k-th image you need

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).

Display the image

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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