[Neuroimaging] chainging sform and save back image

Thomas Vincent 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
other fields.

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.

Thomas.


Le jeu. 31 janv. 2019 05 h 39, federico nemmi <federico.nemmi at gmail.com> a
écrit :

> 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
> .metadata["header"]["sform_code"]
>
> 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
>
> F.
> --
> Federico Nemmi, PhD
>
> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20190131/ff70cab3/attachment.html>


More information about the Neuroimaging mailing list