Layering multiple images in 3D-space

后端 未结 3 1411
生来不讨喜
生来不讨喜 2020-12-17 22:43

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 vis

相关标签:
3条回答
  • 2020-12-17 23:05

    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

    0 讨论(0)
  • 2020-12-17 23:15

    If I understand you correctly, you can use the slice() or contourslice() functions to do this.

    Check out this example: http://www.mathworks.com/help/matlab/visualize/techniques-for-visualizing-scalar-volume-data.html

    0 讨论(0)
  • 2020-12-17 23:20

    The function you're looking for is the patch function. By way of example:

    x=[1 1 6]; y=[2 7 2]; z=[1 1 -1];
    

    This specifies a triangle (three points), and the coordinates of the vertices are (1,2,1), (1,6,1), and (6,2,-1). If you would add a fourth point to each vector it would be a rectangle, with the new vertex at the new x,y,z coordinate.

    To answer your posted question directly, you can plot a number of rectangles for each variable simply by using a multidimensional array for x, y, and z, where each column specifies a different polygon. In practice, this works as follows:

    % plot two rectangles
    x = [1 1 1 1;
        1 1 1 1;
        4 4 4 4;
        4 4 4 4;];
    
    y = [1 1 1 1;
        2 2 2 2;
        2 2 2 2;
        1 1 1 1;];
    
    z = [1 2 3 4;
        1 2 3 4;
        1 2 3 4;
        1 2 3 4;];
    
    patch(x,y,z,'w');
    

    Which makes:

    Four stacked rectangles

    There are options you can use to add color to the polygons, check the docs.

    0 讨论(0)
提交回复
热议问题