Converting 3D matrix to multiple images

Assume i have a 3D matrix with dimesions 32x32x500.
How can i convert this matrix into 500 tif images with dimensions 32x32?

 Accepted Answer

DGM
DGM on 23 Mar 2021
Edited: DGM on 23 Mar 2021
I'm sure somebody has volumetric import/export tools to do this, but this is a basic approach:
numpages=size(inpict,3);
for p=1:numpages
imwrite(inpict(:,:,p),sprintf('image_slice_%03d.tiff',p))
end
This will give each filename a zero-padded number. Consider adding a destination directory to the specified path, otherwise everything is dumped into the current working directory.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Asked:

on 23 Mar 2021

Edited:

DGM
on 23 Mar 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!