1

I should represent a 3D volume image from 2D images in Matlab. The number of 2D images is 90 images in DICOM format. Besides, the each picture size is 512 * 512. This task is about the distance between slices in the Z-axis. This is my following code:

**

clear variables
clear all
close all
names=dir('C:\Users\User\Desktop\Projekt\2-DICOM-Daten von einem Cone-Beam CT (CBCT)\CT.Test CatPhan 
CBCT A\*.dcm');
for i=1:size(names,1) %names is a struct consists of 90 * 1.
       
I(:,:,i)=dicomread(strcat('C:\Users\User\Desktop\Projekt\2-DICOM-Daten von einem Cone-Beam CT 
 (CBCT)\CT.Test CatPhan CBCT A\',names(i).name));
  
for j=1:size(names,1)
Img_3D=surface('XData',[0 256;0 256],'YData',[0 0;256 256],'ZData', 
[jj;jj],'CData',flipdim(im2double(I(:,:,i)),1),'FaceColor','texturemap','EdgeColor','none');
colormap(gray) 
xlabel('x')
ylabel('y')
zlabel('z')
end
end

**

I have to cancel the program so that it gives me the picture. otherwise it takes longer without adding a picture. When the program quits, it shows an image volume, but you have the same image (completely black). Nevertheless, 90 of the original images are different. I uploaded 2 pictures.enter image description here enter image description here I don't know where my fault is. I would be very grateful for your help

Amit Joshi
  • 15,448
  • 21
  • 77
  • 141

1 Answers1

1

You can slightly adapt your surface() call:

% Simulate OP's data with example data supplied by the Image Processing Toolbox
[alldata,cmap]=dicomread('US-PAL-8-10x-echo.dcm');
I=nan(size(squeeze(alldata)));
for i=1:size(alldata,4) %although not necessary in this example, this loop tries to mimic the structure of OP's code
  I(:,:,i)=alldata(:,:,:,i); %this line corresponds to OP's dicomread(strcat(...))
end
clear i;

for i=1:size(alldata,4)
  Img_3D=surface('XData',(1:size(I,2))-1,'YData',(1:size(I,1))-1, ...
    'ZData',(i-1)*ones(size(I(:,:,i))),'CData',flipud(im2double(I(:,:,i))), ...
    'FaceColor','texturemap','EdgeColor','none');
end
colormap(cmap);
clear i I alldata cmap;
xlabel('x');
ylabel('y');
zlabel('z');
zlim([-Inf Inf]);
view(30,30);

The updated code now produces an image with stacked slices:

Image

Vicky
  • 969
  • 1
  • 11
  • 19
  • Thank you for your answer. :) I would like to ask you if you have any idea how to get from 3D images in 3D matrix. i mean that every pixel in the picture is represented as a value and not color. – Natali Graß Mar 14 '21 at 17:15
  • You're welcome! Do you mean plotting a 3D image with voxel intensities printed out as numbers? If so, unless you have something like a 16x16x4 or some other very small image, I guess the result would end up being cluttered beyond any hope of decoding where each number belongs... – Vicky Mar 14 '21 at 18:06