0
votes

I have a 4-d matrix contains 1000 pictures. The shape of matrix is 1000*32*32*3 (1000 is the number of pictures, 32*32 is a 2-d pixel values, 3 is RGB-3 channels).

I was wondering how to display one channel 32*32 values for a picture? or 3 channels 32*32*3?

and can matlab plot the 32*32? or 3 pictures for 3 channels of 32*32?

1
RGB-3 channels? are you refering that the 32 X 32 is the pixel count of a color picture? if so, you can simply use imshow() to see the image. Also do you want to show one picture out of 1000 that you have? - RC0993
thx, I just want to show one picture as an example to see what it looks like. - HAO CHEN
Okay simply use imshow(A(1,:,:,:)); - RC0993
I would suggest permuting the dataset (newA = permute(A, 2,3,4,1);) so that the image ID is last. Then, if you want to plot a certain image with all channels, you'd access newA(:,:,:,404), and if you want just one channel, you'd do newA(:,:,2,404), and no need to squeeze it anymore. - Dev-iL
@HansHirse Probably that should have been reversed. Keeping the answer and deleting the comment. - RC0993

1 Answers

1
votes

In general, you use the imshow command for showing an image, either single-channel (grayscale) or multi-channel (color). In case, you have multiple images stored in the way, you describe, you need to index a specific (grayscale or color) image (or color channel), and possibly need the squeeze command to remove dimensions of length 1, which might cause problems with imshow.

Please see the following code snippet using some mock-up data:

% Mock-up data.
A = uint8(round(255 * rand(1000, 32, 32, 3)));

% Select I-th image.
I = 25;

figure(1);

% Show I-th RGB image.
subplot(2, 2, 1);
imshow(squeeze(A(I, :, :, :)));

% Show I-th red channel image.
subplot(2, 2, 2);
imshow(squeeze(A(I, :, :, 1)));

% Show I-th green channel image.
subplot(2, 2, 3);
imshow(squeeze(A(I, :, :, 2)));

% Show I-th blue channel image.
subplot(2, 2, 4);
imshow(squeeze(A(I, :, :, 3)));

Output:

Output