3D voxel display in matlab

I have a grid, this is 3D and it stores the number.

Here is an example of my grid if it is 2 * 2 * 2:

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

The number 0 is usually the number that I would like to represent with color or nano, if there is no voxel. What I would like to do is show a grid of voxels with a matrix, as in the following figure:

enter image description here

Except that the vocals should be colored by the number in the cell.

Does anyone know how to do this if there is a library or some way to write it yourself?

+6
source share
2 answers

So, I found out that you can do this as follows:

 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 display a gray scale voxel representation as follows:

enter image description here

Now I just need help for the color to work.

+5
source

The complete source code is shown below for building cubes in different colors. Remember that for color information, we must have a Float value between <0.1>. Thus, the input volume is normalized to shift the intensity values โ€‹โ€‹in this range, and then a plotcube script is used to display individual cubes. Script Used to get color @ Use the Matlab color scheme to convert float to RGB . Building 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 
0
source

Source: https://habr.com/ru/post/921259/


All Articles