【问题标题】:3D voxel Display in matlabmatlab中的3D体素显示
【发布时间】:2012-07-23 10:53:00
【问题描述】:

我有一个网格,它是 3D 的,它存储一个数字。

这是我的网格的一个例子,如果它是 2*2*2:

(:, :, 1) -> [0, 0;
              0, 0]
(:, :, 2) -> [0, 0;
              0, 0]

如果那里不存在体素,数字 0 通常是我想用 color 或 nan 表示的数字。我想做的是用matlab显示一个体素网格,如下图所示:

除了元音应该用单元格中的数字着色。

如果有库或自己编写的方法,有谁知道如何做到这一点?

【问题讨论】:

    标签: matlab voxel


    【解决方案1】:

    所以我发现你可以这样做:

    for x = 1:GridSize(1)
        for y = 1:GridSize(2)
            for z = 1:GridSize(3)
    
                if (~isnan(VoxelGrid(x, y, z)))
    
                    cubeLength = VoxelGrid.resolution;
    
                    plotcube(   [cubeLength cubeLength cubeLength], ...
                                [x, y, z], ...
                                0.9, ...
                                [colour, colour, colour])
                 end
             end
         end
     end
    

    这将打印出像这样的灰度体素表示:

    现在我只需要一些帮助才能使颜色正常工作。

    【讨论】:

    【解决方案2】:

    下面给出了完整的源代码,以不同颜色绘制立方体。请记住,为了获取颜色信息,我们必须使浮点值介于 之间。因此,输入体积被归一化以在此范围内移动强度值,然后 plotcube 脚本用于显示单个立方体。 用于获取颜色的脚本是@Use matlab colour scheme to convert float to RGB。绘制单个立方体是@http://www.mathworks.com/matlabcentral/fileexchange/15161-plotcube

    %PLOTCUBE(EDGES,ORIGIN,ALPHA,COLOR)
    
    VoxelGrid(:,:,1)=[5 3;8 1];
    VoxelGrid(:,:,2)=[9 2;7 1];
    
    %VoxelGrid=round(20*rand(8,8,8)); %Uncomment this line to display dense volume
    
    GridSize=size(VoxelGrid);
    for x = 1:GridSize(1)
        for y = 1:GridSize(2)
            for z = 1:GridSize(3)
                if (~isnan(VoxelGrid(x, y, z)))
                    cubeLength = 1;
                    f = VoxelGrid(x,y,z)/max(max(max(VoxelGrid)));
                    cm = colormap; % returns the current color map
                    colorID = max(1, sum(f > [0:1/length(cm(:,1)):1])); 
                    colour = cm(colorID, :); % returns your color
                    plotcube([cubeLength cubeLength cubeLength],[x, y, z],0.9,[colour]);
                 end
             end
         end
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-06
      • 2016-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-19
      • 1970-01-01
      • 2021-06-05
      相关资源
      最近更新 更多