Last active
May 20, 2021 15:17
-
-
Save sarthakpati/73c8ffd7586e715680f3679a791bbec3 to your computer and use it in GitHub Desktop.
This file contains 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