[Neuroimaging] chainging sform and save back image
20100thomas at gmail.com
Thu Jan 31 06:22:18 EST 2019
I think the sform is adapted when saving to maintain some consistency with
The easiest way to make it work is to copy the data from img_to_change into
ref_image and then save ref_image to a new file.
Le jeu. 31 janv. 2019 05 h 39, federico nemmi <federico.nemmi at gmail.com> a
> Hi everyone,
> I am trying to change the sform of an image to those of another image and
> save the first image back as a nifti file.
> To do so I do something in the line of
> > import nipy as ni
> > img_to_change = ni.load_image("my_image_to_change.nii")
> > ref_image = ni.load_image("my_ref_image.nii")
> > img_to_change .metadata["header"]["sform_code"] = ref_image
> When I wheck now the value of the sform code for the first image it is
> indeed equal to the value of the sform code in the reference image.
> However, if I now save the first image with
> >ni.save_image(img_to_change, "modified_img.nii")
> load it back
> >new_img = ni.load_image("modified_img.nii")
> and check the sform code, this is as in the original image !
> Am I missing something, is there a step that I skipping between changing
> the header of the first image and save it ?
> Thank in advance
> Federico Nemmi, PhD
> Neuroimaging mailing list
> Neuroimaging at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Neuroimaging