如何在Matlab中以堆栈样式绘制多个2D图像?

Mr.*_*ter 2 matlab image-processing

在Matlab中,我想绘制几个2D图像(I(x,y)格式的二维矩阵中的所有数据).我知道对于单个图,imagesc(I)可以实现所需的图像.但是,现在,我得到了一些图像,并希望将它们放入堆栈格式,就像示例中显示的图像一样

Hok*_*oki 5

正如您所暗示的,对您的问题最有用的功能是:slice.您还应该阅读这篇Mathworks文章:Exploring Volumes with Slice Planes它提供了有关如何使用切片的更多示例.

在您的情况下,您拥有每个切片的数据(每个图像都是切片),您只需将它们打包在一起,因此Matlab会将它们解释为体积数据.

由于您没有提供任何样本数据,我必须生成一个小样本.我将使用Matlab函数flow生成体积数据并从中提取4个图像(4个切片):

%% Generate sample images
[x,y,z,v] = flow; %// x,y,z and v are all of size [25x50x25]

im1 = v(:,:,5);  %// extract the slice at Z=5.  im1 size is [25x50]
im2 = v(:,:,10); %// extract the slice at Z=10. im2 size is [25x50]
im3 = v(:,:,15); %// extract the slice at Z=15. im3 size is [25x50]
im4 = v(:,:,20); %// extract the slice at Z=20. im4 size is [25x50]

hf = figure ;
subplot(221);imagesc(im1);title('Z=5');
subplot(222);imagesc(im2);title('Z=10');
subplot(223);imagesc(im3);title('Z=15');
subplot(224);imagesc(im4);title('Z=20');

%// This is just how I generated sample images, it is not part of the "answer" !
Run Code Online (Sandbox Code Playgroud)

这给你4个简单的图像: 在此输入图像描述


现在真的很有趣.将所有图像堆叠在一个矩阵中,就好像它们只是切片一样:

M(:,:,1) = im1 ;
M(:,:,2) = im2 ;
M(:,:,3) = im3 ;
M(:,:,4) = im4 ;
Run Code Online (Sandbox Code Playgroud)

你现在有一个矩阵M [25x50x4].如果你有太多的图像,你可以制定一个循环来叠加它们.

从那以后,只需要打电话slice即可获得想要的照片.查看文档以探索所有可能的渲染选项.一个简单的例子是:

hf2 = figure ;
hs = slice(M,[],[],1:4) ;
shading interp
set(hs,'FaceAlpha',0.8);
Run Code Online (Sandbox Code Playgroud)

哪个产生: 在此输入图像描述


注意:这使用默认索引,这应该适合您描述的问题(只是堆叠一些图像).如果您希望您的音量具有真实坐标,则可以使用该坐标系建立坐标系ndgrid.例如:

[xs,ys,zs] = ndgrid( 1:25 , 1:50 , 1:4 ) ;
Run Code Online (Sandbox Code Playgroud)

将创建一个大小的网格/坐标系[25x50x4].只需替换数字即可构建所需的网格坐标.