Forked from sarthakpati/read_and_write_nifti_using_simpleitk.py
Created
August 14, 2020 05:40
-
-
Save meghbhalerao/fc8d7efab1478f77cb889c3ad393c009 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SimpleITK as sitk | |
# read image | |
inputImage = sitk.ReadImage('/path/to/input.nii.gz') | |
# get result in the form of a numpy array | |
npa_res = my_algorithm(sitk.GetArrayFromImage(inputImage)) # my_algorithm does something fancy | |
# Converting back to SimpleITK (assumes we didn't move the image in space as we copy the information from the original) | |
result_image = sitk.GetImageFromArray(npa_res) | |
result_image.CopyInformation(inputImage) | |
# write the image | |
sitk.WriteImage(result_image, '/path/to/result.nii.gz') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment