<div dir="ltr">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...</div><div class="gmail_extra"><br><div class="gmail_quote">2016-06-27 8:04 GMT-04:00 Samuel St-Jean <span dir="ltr"><<a href="mailto:stjeansam@gmail.com" target="_blank">stjeansam@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>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.<br><br></div>- sform is identical<br></div>- sform name changed from <br><br>sform_name     Scanner Anat<br>sform_code     1<br><br></div>to<br><br>sform_name     Aligned Anat<br>sform_code     2<br><br><div><div><div>- some qform fields went from <br><br>qform_name     Scanner Anat<br>qform_code     1<br>qto_xyz:1      1.796652  0.000000  0.000000  -115.754318<br>qto_xyz:2      0.000000  1.795833  -0.054337  -90.885376<br>qto_xyz:3      0.000000  0.054236  1.799180  54.572971<br><br></div><div>to <br><br>qform_name     Unknown<br>qform_code     0<br>qto_xyz:1      1.796652  0.000000  0.000000  0.000000<br>qto_xyz:2      0.000000  1.796652  0.000000  0.000000<br>qto_xyz:3      0.000000  0.000000  1.800000  0.000000<br><br></div><div>Which leaves me wondering what is to be trusted in these fields. Seems like the translation of origin in qform changed (and the name is unknown, so nibabel ignores it on loading), but the sform name changed without changing the actual matrix and now has the translation of the qform. Is there a way to know how these fields are consistent when recreated by nibabel versus the original provided in the (now stripped) header? Or maybe the fsl suite just does not respect some convention I am unaware of (like trusting undefined qform over sform or something else like that), which is also possible, and would fall out of scope of this mailing list.<span class="HOEnZb"><font color="#888888"><br><br></font></span></div><span class="HOEnZb"><font color="#888888"><div>Samuel<br></div></font></span></div></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">2016-06-24 8:35 GMT+02:00 Samuel St-Jean <span dir="ltr"><<a href="mailto:stjeansam@gmail.com" target="_blank">stjeansam@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
So this is probably gonna look as a confused question because I still do not fully understand the issue myself. Anyway, reading upon <a href="https://github.com/nipy/nibabel/pull/90" rel="noreferrer" target="_blank">https://github.com/nipy/nibabel/pull/90</a> and playing with loading a nifti and saving it back, it seems like sometimes the affine, sform and qform do not fully agree upon something and end up overwriting each other.<br>
<br>
This also seems to only happen with data that went through fsl, like the HCP datasets. So basically a normal pipeline involving nibabel is like<br>
<br>
<br>
volume = nib.load('my_data.nii.gz')<br>
data = volume.get_data()<br>
affine volume.get_affine()<br>
<br>
## Do stuff on data<br>
<br>
nib.save(nib.Nifti1Image(data, affine),'my_new_data.nii.gz')<br>
<br>
<br>
Note how I did not save the header in this case. Now, for almost all cases, this works fine and a new header get created. And now for the question :<br>
<br>
Is it a bad idea to strip out the header (since dtype, pixdim and other things might change depending on the processing involved)?<br>
Is it possible to save back exactly the same header / sform / qform so that data won't be flipped in e.g. fslvew afterward? Is it just because software don't play well together or there is an unseen issue I don't get here?<br>
<br>
I also remember a few years back playing the whole afternoon with get/set qform and sform rewriting our affines everytime, so I though might as well ask everyone since we never fully figured out the logic between what sets the affine in the header and why.<br>
<br>
<br>
Thanks for reading,<br>
<br>
Samuel<br>
<br>
</blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Neuroimaging mailing list<br>
<a href="mailto:Neuroimaging@python.org">Neuroimaging@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/neuroimaging" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/neuroimaging</a><br>
<br></blockquote></div><br></div>