[Neuroimaging] [nibabel] sform/qform flipping left - right in the affine and (possibly) fsl

Samuel St-Jean stjeansam at gmail.com
Tue Jun 28 02:50:30 EDT 2016


I'll need to play a bit with it today and ask some guy about the 
flipping, I am reporting for someone else actually. So, it seems to be 
harmless to put back the header in the case of unchanged affine (as it 
is in my situation), could be that other software downstream does not 
really like something else. I did not reuse it because of dtypes, 
voxelsize and other things which may wildly change on processed data.


Anyway, this example is using your case number 1, no header, affine is 
gotten from get_affine. Of course it was not modified during the 
processing, and I end up with a different sform/qform. Accoridng to your 
first point, I expected them to be identical, but I end up with a 
sligthly different (and diagonal) qform. They also have different names, 
so ifthey were set to the same thing I would expect them to be pristine 
copies.

That's a bit troublesome now as JC pointed out, since we all use the 
same set of scripts for the  heavy processing, which don't reuse headers 
as I can remember. Does not seem to cause any problem for us, don't want 
to receive hate mail by other people using some of our stuff and saying 
we broke their data though.

Are sform and qform set to match the affine in exactly the same way, or 
does some transformation is applied and then they are identical? I went 
through the info on the nibabel website about headers and affine, so 
maybe I just missed it also if anyone has other info to add.


Le 2016-06-27 à 20:20, Matthew Brett a écrit :
> Hi,
>
> On Mon, Jun 27, 2016 at 6:06 AM, Jean-Christophe Houde
> <jean.christophe.houde at gmail.com> wrote:
>> Just a quick note: qform_code = 0 normally means that it is not set, so I'm
>> surprised to see some values in your last qto_xyz...
>>
>> 2016-06-27 8:04 GMT-04:00 Samuel St-Jean <stjeansam at gmail.com>:
>>> So, to add a more practical example to what I outlined above, seems like
>>> saving a dataset in this manner preserves the sform, but changes the qform.
>>> According to the doc, they should both provide the same information in
>>> reconstructing the affine (possible from different origins). So I compared
>>> the header of an original nifti file and the same thing after saving it
>>> without headers, and here are the interesting parts.
>>>
>>> - sform is identical
>>> - sform name changed from
>>>
>>> sform_name     Scanner Anat
>>> sform_code     1
>>>
>>> to
>>>
>>> sform_name     Aligned Anat
>>> sform_code     2
>>>
>>> - some qform fields went from
>>>
>>> qform_name     Scanner Anat
>>> qform_code     1
>>> qto_xyz:1      1.796652  0.000000  0.000000  -115.754318
>>> qto_xyz:2      0.000000  1.795833  -0.054337  -90.885376
>>> qto_xyz:3      0.000000  0.054236  1.799180  54.572971
>>>
>>> to
>>>
>>> qform_name     Unknown
>>> qform_code     0
>>> qto_xyz:1      1.796652  0.000000  0.000000  0.000000
>>> qto_xyz:2      0.000000  1.796652  0.000000  0.000000
>>> qto_xyz:3      0.000000  0.000000  1.800000  0.000000
> Just to clarify - the rules for sform / qform are the following:
>
> If you don't pass a header to image construction, then the input
> `affine` gets set into both sform and qform, with default sform /
> qform output codes.
>
> If you do pass a header, and the input `affine` is the same as the
> affine implied by the header (either via the sform or qform), or the
> input affine is None, then the header (therefore sform / qform) is
> unchanged.
>
> If you do pass a header, and the affine is different from that implied
> by the header, both sform and qform get set to match the input affine.
>
> Does that explain what you are seeing?
>
> Cheers,
>
> Matthew
> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging



More information about the Neuroimaging mailing list