[Neuroimaging] Change sform and save

Markus Gramer Markus.Gramer at kuleuven.be
Mon Aug 3 14:38:45 CEST 2015


Thanks, for the fast reply! This indeed solves my issue!

Cheers,

Markus

On 03/08/15 14:30, "Neuroimaging on behalf of Matthew Brett"
<neuroimaging-bounces+markus.gramer=kuleuven.be at python.org on behalf of
matthew.brett at gmail.com> wrote:

>Hi,
>
>On Mon, Aug 3, 2015 at 1:19 PM, Markus Gramer <Markus.Gramer at kuleuven.be>
>wrote:
>> Hi there,
>>
>> I am new to nibabel (and also python) so maybe I am making an obvious
>> mistake, but I could not find anything in the manual that would help meŠ
>>
>> I am trying to update the sform in a Nifty1 image and save it with:
>>
>> def update_sform(file_in, file_out, affine_out):
>>
>> img = nib.load(file_in)
>>
>> img_hdr = img.header
>>
>> img_hdr.set_sform(affine_out)
>>
>> nib.save(img,file_out)
>>
>>
>> However, I realised that due to the comparison between current header
>>and
>> affine:
>>
>>
>> np.allclose(self._affine, hdr.get_best_affine()) [spatialimages.py, line
>> 426]
>>
>>
>> The sform in the header is reset to the affine when I am saving the
>>image.
>> Is there a way to directly set the affine? Or any other method that I
>>can
>> use to achieve this?
>
>Sorry - it should be better documented, but I think you want:
>
>img.set_sform(affine_out)
>
>This sets the affine for the image as well as the sform,
>
>Cheers,
>
>Matthew
>_______________________________________________
>Neuroimaging mailing list
>Neuroimaging at python.org
>https://mail.python.org/mailman/listinfo/neuroimaging



More information about the Neuroimaging mailing list