简体   繁体   English

Matlab:如何从4-D矩阵进行绘图

[英]Matlab: how to plot from 4-d matrix

I have a 4-d matrix contains 1000 pictures. 我有一个包含1000张图片的4维矩阵。 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). 矩阵的形状为1000 * 32 * 32 * 3(1000是图片数,32 * 32是2 d像素值,3是RGB-3通道)。

I was wondering how to display one channel 32*32 values for a picture? 我想知道如何为图片显示一个通道的32 * 32值? or 3 channels 32*32*3? 或3个通道32 * 32 * 3?

and can matlab plot the 32*32? Matlab可以绘制32 * 32吗? or 3 pictures for 3 channels of 32*32? 或3张32 * 32通道的3张图片?

In general, you use the imshow command for showing an image, either single-channel (grayscale) or multi-channel (color). 通常,您可以使用imshow命令显示单通道(灰度)或多通道(彩色)的图像。 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 . 如果您描述的方式中存储了多张图像,则需要索引特定的(灰度或彩色)图像(或彩色通道),并且可能需要squeeze命令删除长度为1的尺寸,这可能会导致问题用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: 输出:

产量

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

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