Python writing is not working correctly

Hello @sarthakpati,

Based on the following MWE I suspect there is a bug in the underlying ITK implementation (copying the metadata dictionary will resolve your issue, but isn’t what is expected). When it isn’t copied the srow_x, srow_y, srow_z values in the written nifti are all zeros:

import SimpleITK as sitk

base_image = sitk.ReadImage("test_flair.nii.gz")
test_image = sitk.ReadImage("test_001.nii.gz")
test_image.CopyInformation(base_image)
sitk.WriteImage(test_image, "test_new.nii.gz")
test_image_new = sitk.ReadImage("test_new.nii.gz")
print('Expected path:')
print(test_image.GetOrigin())
print(test_image_new.GetOrigin())

base_image = sitk.ReadImage("test_flair.nii.gz")
test_image = sitk.ReadImage("test_001.nii.gz")
test_image.CopyInformation(base_image)
for k in base_image.GetMetaDataKeys():
    test_image.SetMetaData(k, base_image.GetMetaData(k))
sitk.WriteImage(test_image, "test_new.nii.gz")
test_image_new = sitk.ReadImage("test_new.nii.gz")
print('Unexpected path:')
print(test_image.GetOrigin())
print(test_image_new.GetOrigin())

@blowekamp, @hjmjohnson, @dzenanz, any idea what is going on (I’m “at” a conference so didn’t have too much time to dig into this).