HAO CHEN
HAO CHEN

Reputation: 1319

Matlab: how to plot from 4-d matrix

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?

Upvotes: 0

Views: 123

Answers (1)

HansHirse
HansHirse

Reputation: 18925

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

Upvotes: 1

Related Questions