sitk.WriteImage to multiple png files

I can write a 3d sitk Image to a single png, is there a hidden switch to get multiple pngs per 3D image?


Sean Hatton, PhD

You might want itk::ImageSeriesWriter, or its SimpleITK equivalent, itk::simple::ImageSeriesWrite.

Hello @Sean_Hatton

You can provide a set of file names to WriteImage and it will save slices along the z axis, code below:

import SimpleITK as sitk
import os

image = X

output_dir = '.'
slice_prefix = 'slice'
sitk.WriteImage(image, [os.path.join(output_dir, f"{slice_prefix}{i:03d}.png") for i in range(image.GetDepth())])

Great, that worked a dream! Thank you!

1 Like