0

I have 170 slices of 512 x 512 image in binary form (manual segmentation from a data set of medical images). I would like to plot a 3 dimensional visualization/model of the object, by stacking these 170 slices of image together.

I used concatenation function to stack all the 170 images into one matrix, D. My coding as below:

C = cell(1, 170);
for k = 1:170;
    % Create a mat filename, and load it into a structure called matData.
    matFileName = sprintf('AAAmanual%d.mat', k);
    if exist(matFileName, 'file')
        load(matFileName);
        C{k} = BW;
    else
        fprintf('File %s does not exist.\n', matFileName);
    end
end

D = cat(3, C{:});

I'm not sure whether this is the correct way to do so. So i need your advice and help to proceed from here. How should i write in Matlab code, or what is the function suitable to use to visualize the model?

enter image description here

I got something plotted out using smoothed surface, but got an error mentioning out of memory. The coding for smoothed surface as follow:

patch(isocaps(D,.5),...
   'FaceColor','interp','EdgeColor','none');
p1 = patch(isosurface(D,.5),...
   'FaceColor','blue','EdgeColor','none');
isonormals(D,p1)
view(3); 
axis vis3d tight
camlight left; 
colormap jet
lighting gouraud

Result from smooth3 plot: enter image description here

How should i overcome the out of memory problem? or is there a better way to plot this?

Onered
  • 43
  • 1
  • 9
  • Is the pixel distance and the slice distance the same? In most applications the distance between the slices is higher than the distance between the pixels within one slice. – Daniel Feb 28 '15 at 10:04
  • Is these distance important? how is the distance being used in plotting the model? can you let me know how to plot if the distance between the slices is different than the distance between the pixels within one slice? thanks alot.. – Onered Feb 28 '15 at 10:09
  • If the slice distance is for example twice the pixel distance but you don't reflect this in your code, a circle will be displayed as an ellipse. – Daniel Feb 28 '15 at 10:11
  • Try this code: http://stackoverflow.com/questions/11642426/3d-voxel-display-in-matlab It does not implement different scaling but you could easily extend it. – Daniel Feb 28 '15 at 10:15
  • Sorry @Daniel, i still cant get it. Perhaps that's not exactly what i wanted to do. Actually i want to post a picture to show the end result i want but i have not enough reputation yet to post any image. Actually the end result of stacking all the slices is an aorta, i want to write the Matlab code to visualize the model. Is there anyway i can do so? – Onered Feb 28 '15 at 11:01
  • Upload it somewhere else like imgur or dropbox. – Daniel Feb 28 '15 at 11:10
  • I see. Try this link to Dropbox. I've uploaded the picture there. https://www.dropbox.com/s/pnbj8kvf9rhaqds/3D.jpg?dl=0 – Onered Feb 28 '15 at 12:32
  • What is the distance between two pixels in cm? What is the distance between two slices in cm? Unless these numbers are equal you must add scaling to the code I linked. Nevertheless, try it without scaling first. The output will be slightly different as the linked code works with voxels (3d pixels) and the images seems to calculate a smoothed surface. – Daniel Feb 28 '15 at 15:14
  • Thanks @Daniel. Pixel spacing is around 0.074cm. I'm not sure about the distance between two slices, because i used concatenation to combine them together, is there a default value for this by Matlab? How do i add scaling to the code you link? i cant really understand those code yet. – Onered Mar 01 '15 at 02:12

1 Answers1

0

Here is an updated version including scaling:

%just some random input data
VoxelGrid=randi(100,30,20,30)==1;
%x axis: 1 voxel is 1 cm
%y axis: 1 voxel is 2cm
%z axis: 1 voxel is .5 cm
resolution=[1,2,.5];

GridSize=size(VoxelGrid);
for x = 1:GridSize(1)
    for y = 1:GridSize(2)
        for z = 1:GridSize(3)
            if VoxelGrid(x, y, z)
                %http://www.mathworks.com/matlabcentral/fileexchange/15161-plotcube
                plotcube(   resolution, ...
                            [x, y, z].*resolution, ...
                            0.4, ...
                            [1, 0, 0])
             end
         end
     end
 end
Daniel
  • 36,610
  • 3
  • 36
  • 69
  • Thanks...i got some cube-like plot.but i think it's not the look i wanted...i want something above, the one I plot using smooth function.. – Onered Mar 04 '15 at 13:29