MATLAB: How to write each slices from volume in MATLAB into jpg format

image segmentationMATLAB

Hello dear may you please help for solving a problem: I have 3D Volume dataset in .niit format I read this data in MATLAB and also can show each slice from this volume….but I'm unable to write each slice in jpg /2D form How we can write each slice from volume by using imwrite in MATLAB?

Best Answer

You probably don't want to do that anyway, unless you use lossless jpeg2000 format. Use PNG for lossless compression
for sliceIndex = 1 : size(image3d, 3)
thisSlice = image3d(:,:,sliceIndex);
filename = sprintf('Slice #%d.png', sliceIndex);
imwrite(thisSlice, filename);
end
image3d is your 3-D image array.