3D voxel Display in matlab

雨燕双飞 提交于 2019-12-01 05:45:00

So I found out you can do it like this:

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

This will print out a grey scale voxel representation like this:

Now i just need some help getting the colour working.

Mozzam Jawaid

Complete source code is given below plotting cubes in Different colors. Remember that for obtaining the colour information, we must have Float value between <0,1>. So the input volume is normalized to shift intensity values in this range and then plotcube script is used for displaying individual cubes. Script Used for obtaining colour is @ Use matlab colour scheme to convert float to RGB. Plotting individual cubes is @ 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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!