在3D空间中分层多个图像 [英] Layering multiple images in 3D-space

查看:612
本文介绍了在3D空间中分层多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有一个大小为49x49x5的矩阵I,对应于沿着第三维堆叠的5个大小为49x49的图像,因此我们总共有5个图像。这些图像应该可视化3D空间中的气体密度,因此我们可以将每个图像视为不同位置的房间的剖面图。



是否有任何图像在MATLAB中制作一个图形的方法,其中所有5个图像显示为悬挂在它们来自的3D空间中?



这是一张有希望让我更清楚的图片:

解决方案

请考虑以下示例。它使用低级 SURFACE 功能绘制堆积图像:

 %#创建堆叠图像(我只是重复相同的图像5次)
img = load('clown') ;
I = repmat(img.X,[1 1 5]);
cmap = img.map;

%#coordinates
[X,Y] = meshgrid(1:size(I,2),1:size(I,1));
Z = 1(大小(I,1),大小(I,2));

%#将每个切片绘制为纹理映射表面(沿Z维度堆叠)
表示k = 1:size(I,3)
surface('XData ',X-0.5,'YData',Y-0.5,'ZData',Z。* k,...
'CData',I(:,:,k),'CDataMapping','direct' ,...
'EdgeColor','none','FaceColor','texturemap')
end
colormap(cmap)
view(3),box on,axis紧平方
套装(gca,'YDir','反向','ZLim',[0尺寸(I,3)+1])$ ​​b $ b

我正在使用索引彩色图像(使用直接颜色映射),但可以轻松更改为使用灰度图像(使用缩放颜色映射)。



现在,如果你想要像你在问题中看到的那样排列3D空间,只需要交换Y和Z尺寸(沿着Y维而不是Z维堆叠的图像)。 / p>

一般情况下,为了更好地控制视角,请使用相机操作功能





Suppose we have a matrix I of size 49x49x5, corresponding to 5 images of size 49x49 stacked along the third dimension so we have a total of 5 images. These images should visualize the density of a gas in a 3D space, so we can think of each image as a section cut of the room at different locations.

Is there any way to make a figure in MATLAB where all 5 images are shown as hanging in the 3D space they "came from"?

Here is an image hopefully making it clearer what I am after:

解决方案

Consider the following example. It uses the low-level SURFACE function to plot stacked images:

%# create stacked images (I am simply repeating the same image 5 times)
img = load('clown');
I = repmat(img.X,[1 1 5]);
cmap = img.map;

%# coordinates
[X,Y] = meshgrid(1:size(I,2), 1:size(I,1));
Z = ones(size(I,1),size(I,2));

%# plot each slice as a texture-mapped surface (stacked along the Z-dimension)
for k=1:size(I,3)
    surface('XData',X-0.5, 'YData',Y-0.5, 'ZData',Z.*k, ...
        'CData',I(:,:,k), 'CDataMapping','direct', ...
        'EdgeColor','none', 'FaceColor','texturemap')
end
colormap(cmap)
view(3), box on, axis tight square
set(gca, 'YDir','reverse', 'ZLim',[0 size(I,3)+1])

I am using indexed color images (with direct color mapping), but it can be easily changed to use grayscale images (with scaled color mapping).

Now if you want to get the 3D space arranged like you have shown in your question, simply interchange the Y and Z dimensions (images stacked along the Y-dimension instead of the Z-dimension).

In general, to have more control on the viewing angle, use the camera manipulation functions.

这篇关于在3D空间中分层多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆