DevelopmentalImagingMCRI / karawun

Convert tractography studies from mrtrix into dicom for use in navigation software
Apache License 2.0
13 stars 4 forks source link

Exception handler: ValueError - dmn.nii.gz: Unknown qform code - stopping #32

Closed dundermain closed 1 year ago

dundermain commented 1 year ago

Whenever I am trying to convert some network maps it is throwing this error. It is working fine while converting other nifti images like 3D T1 or T2 but this error shows up when I use network maps. How to resolve this one?

richardbeare commented 1 year ago

Thanks for the report. What do you mean when you say "network map"? The qform code and associated matrix govern the interpretation of the orientation of the data, so karawun won't convert data without it. If your network map is designed to be overlaid on or derived from another 3D nifi file then you can copy the geometry information (including qform) from that file using fslcpgeom. For example, if the network map has the same voxel sizes, image dimensions and orientation as the T1, then copy the geometry from the T1. Confirm that the display is correct in whatever package you are using to generate the nifti files.

dundermain commented 1 year ago

Thanks for the reply @richardbeare . Network maps are the activation maps of a single ROI. For example motor network maps is a 3D Nifti file containing activation from motor regions of a particular subject. Now, I want to convert these network maps to DICOM.

richardbeare commented 1 year ago

OK, that makes sense. You definitely need to copy geometry information from a related nifti, presumably one of the inputs to your processing pipelines. Not sure why you've ended up without geometry information. You may also get away with copying sform to qform if one of them is present. Whatever copying you end up doing, confirm that viewers like mrview or fsleyes overlay the map in the way you expect.

You then have an option to threshold the activation map and pass it via the the --label-file option (which will make it appear as a 3D object in brainlab) or via the nifti argument, in which case it will be interpreted as a regular MR style image (or both).

mb3152 commented 1 year ago

Hi @richardbeare

If my qform and sform affines are the same, would you recommend:

import nibabel as nib
t1= nib.load('t1.nii')
t1.set_qform(t1.affine, code=2)

It works in the pipeline, just wanted to run it by you before I send this to someone with a Brainlab setup to test. Thanks!

richardbeare commented 1 year ago

Probably yes - I rely on mrview to confirm that everything is OK.