Skip to content

Check NII header for affine conformity #86

Description

@levje

Description of feature

When trying to process a specific dataset, I encountered some weird issues for which we could make a check to make sure the pipeline runs correctly. I have a dataset for which the raw data was formatted using: dcm2mnc and then mnc2nii. When carefully looking at the data using fslhd T1w.nii.gz, we notice that the qform fields are well set, but the sform fields are basically empty:

qform_name	Unknown
qform_code	0
qto_xyz:1	2.000000 0.000000 0.000000 0.000000
qto_xyz:2	0.000000 2.000000 0.000000 0.000000
qto_xyz:3	0.000000 0.000000 2.000000 0.000000
qto_xyz:4	0.000000 0.000000 0.000000 1.000000
qform_xorient	Left-to-Right
qform_yorient	Posterior-to-Anterior
qform_zorient	Inferior-to-Superior
sform_name	Unknown
sform_code	1
sto_xyz:1	-1.995318 -0.045280 0.129053 93.241196
sto_xyz:2	0.045251 -1.999487 -0.001916 99.963882
sto_xyz:3	0.129063 0.001008 1.995831 -52.961208
sto_xyz:4	0.000000 0.000000 0.000000 1.000000
sform_xorient	Right-to-Left
sform_yorient	Anterior-to-Posterior
sform_zorient	Inferior-to-Superior

Having the qform (or sform) empty causes some issues down the line when processing with sf-tractomics. We end up comparing the affines of an image like the one above and another image with exactly the same sform, but with filled qform fields (the values of sform and qform are essentially identical). Theoretically, they should have the same affines. However, when loading both images some tools (e.g. nibabel), the affines of both images are different which causes some steps of the pipeline to fail (in my case it was the ants betcrop processing step).

The solution to this problem was to simply run mrtrix's mrconvert ${image} ${image} on all input images to make sure that the sform and qform fields are essentially the same if they were not set.

As an ease of use enhancement to the pipeline, we could potentially, somewhere in a workflow, load the header of the NIFTI files to quickly assess if the file requires fixing/converting or not. If the file needs to be "fixed", then it branches into a channel which is fed into a process which runs something like mrconvert ${image} ${image} -force to make sure the raw input data is conform and won't cause any issues for downstream tasks.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions