[Neuroimaging] chainging sform and save back image

federico nemmi federico.nemmi at gmail.com
Thu Jan 31 07:11:59 EST 2019


Sounds reasonable. I'll give it a try!
F.

Il giorno gio 31 gen 2019 alle ore 12:22 Thomas Vincent <
20100thomas at gmail.com> ha scritto:

> 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
>>
> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging
>


-- 
Federico Nemmi, PhD
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20190131/11db8d39/attachment.html>


More information about the Neuroimaging mailing list