MATLAB: How can I convert 2d images to a 3d image

how can i convert 2d images to a 3d image?Image Processing Toolbox

I have a CT scan file with 51 slices…how can I make a 3d image with this 51 slices?
Is there any toolbox in matlab for this?
I attached this file.

Best Answer

You can use cat()
image3d = cat(3, slice1, slice2, slice3, slice4);
or in a loop where you read in each slice
array3d = zeros(rows, columns, numberOfSlices);
for slice = 1 : numberOfSlices
filename = spritnf('image #%d', slice);
fullFileName = fullfile(folder, filename);
if exist(fullFileName, 'file)
thisSlice = imread(fullFileName);
array3d(:,:,slice) = thisSlice;
end
end
or if you don't know the number of slices in advance,
thisSlice = imread(filename);
if slice == 1
array3d = thisSlice
else
array3d = cat(3, array3d, thisSlice);
end