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
source share