I have 2D slices of a 3D CT image. They are in DICOM
format and there are 250 of them. I want to reconstruct the 3D image with MATLAB. How can I do this in a loop?
/home/amadeus/Desktop/images
Images are named:
IM-0001-0001.dcm IM-0001-0002.dcm IM-0001-0003.dcm ... IM-0001-0250.dcm
Apparantly there is a function just for reading DICOM files: dicomread , I suggest using that to load the images and then store them in a 3D matrix. sprintf can be used to construct the filenames of the images (use %04d
to generate four-digit number with leading zeros).
Assuming all images are aligned and have same size:
N = 250;
img_dir = '/home/amadeus/Desktop/images'
% read the first image separately just to get the size
strfile = 'IM-0001-0001.dcm';
img = dicomread(fullfile(img_dir, strfile));
siz_img = size(img);
% create result matrix:
ct3d = NaN([siz_img N]);
ct3d(:,:,1) = img;
% load all the remaining images and put them in the matrix
for ii=2:N
strfile = sprintf('IM-0001-%04d.dcm',ii);
ct3d(:,:,ii)= dicomread(fullfile(img_dir, strfile));
end
edit: This assumes image are grayscale (2d). In case they're full colour (width x height x 3), you should add another colon operator in the assignment to ct3d
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.