Here are a few lines of code that might be useful...
P = spm_select(1,'nifti'); % Select an NIfTI file
Nii = nifti(P); % Read NIfTI header
Nii.mat % Show the sform matrix
Nii.mat0 % Show the qform matrix
Nii.hdr % Showing the contents of the header itself (note that you can not change the header directly)
Nii.mat0 = Nii.mat; % Copying the sform to the qform
Nii.mat = Nii.mat0; % Copying the qform to the sform
%create(Nii); % Write (or re-write) the header to disk (commented out)
For the Python or C++ users among you, note that the sform matrix is adjusted to account for MATLAB counting voxels from 1..N, rather than the 0..N-1 . This is why Nii.hdr.srow_x (or _y or _z) is slightly different from what it says in Nii.mat0 .
Best regards,
-John
Dear Guillaume,
May I ask how would you apply the change to the
header of the images? Because we found a way,
copying and pasting the "correct" numbers/orientation.
Wondering whether a "better" way does exist?
And yes, the troubes were created when using
different softwares that prioritise the qform orientation
before the sform, like FSL and ITKviewer
Peace,
aran