I have 191 different png images.
How can I convert them into one 3d nifti image?
I have 191 different png images.
How can I convert them into one 3d nifti image?
Here's a SimpleITK python script that can read in a stack of PNG images and output a 3d Nifti image:
import SimpleITK as sitk
import glob
file_names = glob.glob('*.png')
reader = sitk.ImageSeriesReader()
reader.SetFileNames(file_names)
vol = reader.Execute()
sitk.WriteImage(vol, 'volume.nii.gz')
The script assumes that the glob
gets the file names in the proper order. Also the 3-d volume created will have uniform spacing in X, Y, and Z. If the Z spacing is not the same as X and Y, you can call vol.SetSpacing
with whatever the spacing values should be.