2012-07-25 149 views
6

我有一个网格,它是3D,它存储一个数字。3D体素在matlab中的显示

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

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

通常将是如果没有体素存在有一个数字,我想与颜色或NaN来表示数字0 。我想这样做是显示与MATLAB体素网格状如下图:

enter image description here

除将vocels应与细胞的数量进行着色。

有没有人知道如何做到这一点,如果有一个库或一些自己写的方式?

回答

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

现在我只是需要一些帮助越来越颜色工作。

+0

现在从您的其他问题http://stackoverflow.com/questions/11642826/use-matlab-colour-scheme-to-convert-float-to-rgb应用解决方案得到你的颜色 – 2012-07-25 09:50:14

+0

已经完成了,谢谢你的评论。 – 2012-07-25 22:18:30

+0

你能发布完整的源代码来重现结果吗? – mrgloom 2014-12-26 00:30:46

0

下面给出完整的源代码,以不同的颜色绘制立方体。请记住,要获得颜色信息,我们必须使用浮点值在< 0,1>之间。因此,输入音量被归一化以移动该范围内的强度值,然后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