Rotation information in Nifti files

We stumbled across a problem with rotation information in Nifti files.
We have two files, let’s call them T2w.nii.gz and msk.nii.gz, and yes msk.nii.gz is the mask for T2w.
As it should be the two files are identical in dimensions and indeed mrinfo -transform shows the exact same transform for them.
However, we noticed that when we load the files into matlab, the transformation matrices are different.
There are two different places in a nifti file for a transform and I believe mrtrix is only showing the combination of these two.
In matlab I can find:

MRtrix shows:

Is there a way to see (and change if desired) the two individual components of the rotation matrix?

Yes and no. MRtrix will only load one of the two, and if only one is found in the NIfTI header, that’s the one it’ll load. If both are present, it will default to the sform – and also produce a warning on the terminal if they don’t both carry the same information (to within some tolerance).

You can tell MRtrix to default to the qform using the NIfTIUseSform config variable, so that allows you to query one or the other. Note that you don’t need to actually modify the config file for that, you can just specify -config NIfTIUseSform 0 on the command-line.

If you want to see the actual transform without the usual modifications that MRtrix performs by default, you can additionally tweak that using the RealignTransform config variable – i.e. add -config RealignTransform 0 to the command-line.

In terms of modifying those two entries separately, no, MRtrix will always write the same information in both entries, to avoid complications downstream since different packages will likely use different conventions and defaults. FSL’s fsledithd will probably allow you to do that though.


1 Like