How to combine image slices into a NIfTI file

94 Views Asked by At

I have a function which, given a NIfTI file, generates a set of images. How can I essentially reverse that process with another function which takes in these images and creates a NIfTI file from them?

1

There are 1 best solutions below

0
Dave Chen On

You do that with SimpleITK's ImageSeriesReader class. It'd look something like this:

import SimpleITK as sick

reader = sitk.ImageSeriesReader()

reader.SetFileNames(["slice1.png", ..., "sliceN.png"])

volume_image = reader.Execute()

Note that the volume won't have any voxel spacing information, so you might need to call the SetSpacing method

volume_image.SetSpacing([x_spacing, y_spacing, z_spacing])