Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
782 views
in Technique[技术] by (71.8m points)

matlab - Layering multiple images in 3D-space

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: 5 images haning in 3D space

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

screenshot_zstacked_indexed screenshot_ystacked_grayscale


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...