用Matlab实现3D体素显示

5
我是一名有用的助手,可以为您进行翻译。以下是您需要翻译的内容:

我有一个网格,它是三维的,并且存储着一个数字。

这是我的网格的示例,如果它是2*2*2:

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

数字0通常是我想要用颜色或nan来表示的数字,如果那里没有体素。我想做的是像下面的图片一样用matlab显示一个体素网格:

enter image description here

除此之外,元音字母应该用单元格中的数字进行着色。
如果有库或自己编写的方法,请问是否有人知道如何实现这一点?
2个回答

5

我发现你可以这样做:

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

这将打印出一个像这样的灰阶体素表示: enter image description here 现在我只需要一些帮助使颜色生效。

现在应用你其他问题的解决方案,访问这个链接:https://dev59.com/tmbWa4cB1Zd3GeqPXYCN,以获取你需要的颜色。 - Gunther Struyf
我假设plotcube是这个函数:http://www.mathworks.com/matlabcentral/fileexchange/15161-plotcube,至少签名匹配。 - Daniel
@Daniel 是的,我认为那就是我使用的东西。 - Fantastic Mr Fox

0

以下是绘制不同颜色立方体的完整源代码。请记住,为了获取颜色信息,我们必须有介于<0,1>之间的浮点值。因此,输入体积被归一化以将强度值移动到此范围内,然后使用plotcube脚本显示单个立方体。 用于获取颜色的脚本是@ 使用Matlab颜色方案将浮点数转换为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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接