Mtnormalise nan values as balance factors

Dear expert,

I am currently processing diffusion HCP data and I’m getting an error in a few subjects with the mtnormalise command:

mtnormalise: [100%] performing log-domain intensity normalisation
mtnormalise: [ERROR] Non-positive tissue balance factor was computed. Balance factors: -nan -nan -nan

Is there anything I can do to solve this issue? Would removing the nan values in the FODs solve this?

Thank you,

Stefanie

Hi Stefanie,

It’s difficult to know from the error alone what exactly has driven the nonsensical result, so will require a bit of probing the data to diagnose. The first thing you can do is re-run the command with the -debug flag and post the results here, and we’ll see if it yields anything informative.

Would removing the nan values in the FODs solve this?

Not sure to what extent the nature of this question is actually intentional. If you have FOD images that do actually contain NaN values (which would be the exception to the rule), and the compulsory mask input to mtnormalise includes voxels for which there are NaN values in the FOD coefficients, then that could at least conceivably lead to such an error, depending on the intricacies of the code. But something would have to be putting NaN values into the FOD images… So if that turned out to be the case, while we could modify mtnormalise to ignore non-finite values, you’d also want to backtrace exactly how those NaN values made their way into your images, and how whatever mechanism you used to derive your mask image still included such voxels.

Cheers
Rob

Hi Rob,

Thanks a lot for the quick reply.

I re-ran the command with the -debug flag and this is the output:

mtnormalise -mask /data/neuralabc/treste/Mult_dim_quant_WM/source/108525/T1w/Diffusion/nodif_brain_mask.nii.gz wm_fod.mif wm_fod_norm.mif gm_scalar.mif gm_scalar_norm.mif csf_scalar.mif csf_scalar_norm.mif -debug 
mtnormalise: [DEBUG] No config file found at "/etc/mrtrix.conf"
mtnormalise: [DEBUG] No config file found at "/home/remoteuser/treste/.mrtrix.conf"
mtnormalise: [INFO] opening image "/data/neuralabc/treste/Mult_dim_quant_WM/source/108525/T1w/Diffusion/nodif_brain_mask.nii.gz"...                                                                                         
mtnormalise: [DEBUG] transforms_match: FOV difference in scanner coordinates: 0
mtnormalise: [DEBUG] sanitising image information...
mtnormalise: [INFO] Axes and transform of image "/data/neuralabc/treste/Mult_dim_quant_WM/source/108525/T1w/Diffusion/nodif_brain_mask.nii.gz" altered to approximate RAS coordinate system                                 
mtnormalise: [DEBUG] searching for suitable phase encoding data...
mtnormalise: [INFO] image "/data/neuralabc/treste/Mult_dim_quant_WM/source/108525/T1w/Diffusion/nodif_brain_mask.nii.gz" opened with dimensions 145x174x145, voxel spacing 1.25x1.25x1.25, datatype Float32LE               
mtnormalise: [DEBUG] loading image "/data/neuralabc/treste/Mult_dim_quant_WM/source/108525/T1w/Diffusion/nodif_brain_mask.nii.gz"...                                                                                        
mtnormalise: [100%] uncompressing image "/data/neuralabc/treste/Mult_dim_quant_WM/source/108525/T1w/Diffusion/nodif_brain_mask.nii.gz"
mtnormalise: [DEBUG] image "/data/neuralabc/treste/Mult_dim_quant_WM/source/108525/T1w/Diffusion/nodif_brain_mask.nii.gz" loaded                                                                                            
mtnormalise: [DEBUG] image "/data/neuralabc/treste/Mult_dim_quant_WM/source/108525/T1w/Diffusion/nodif_brain_mask.nii.gz" initialised with strides = [ -1 145 25230 ], start = 144, using indirect IO                       
mtnormalise: [DEBUG] sanitising image information...
mtnormalise: [DEBUG] allocating scratch buffer for image "index"...
mtnormalise: [DEBUG] image "index" loaded
mtnormalise: [DEBUG] image "index" initialised with strides = [ -1 145 25230 ], start = 144, using direct IO
mtnormalise: [INFO] mask image contains 767938 voxels
mtnormalise: [DEBUG] image "/data/neuralabc/treste/Mult_dim_quant_WM/source/108525/T1w/Diffusion/nodif_brain_mask.nii.gz" unloaded                                                                                          
mtnormalise: [INFO] opening image "wm_fod.mif"...
mtnormalise: [DEBUG] reading key/value file "wm_fod.mif"...
mtnormalise: [DEBUG] sanitising image information...
mtnormalise: [INFO] image "wm_fod.mif" opened with dimensions 145x174x145x45, voxel spacing 1.25x1.25x1.25x1, datatype Float32LE                                                                                            
mtnormalise: [DEBUG] memory-mapping file "wm_fod.mif"...
mtnormalise: [DEBUG] file "wm_fod.mif" mapped at 0x7efc40f02000, size 658503000 (read-only)
mtnormalise: [DEBUG] image "wm_fod.mif" loaded
mtnormalise: [DEBUG] image "wm_fod.mif" initialised with strides = [ -45 6525 1135350 1 ], start = 6480, using direct IO                                                                                                    
mtnormalise: [DEBUG] initialising threads...
mtnormalise: [DEBUG] launching 28 threads "loop threads"...
mtnormalise: [DEBUG] waiting for completion of threads "loop threads"...
mtnormalise: [DEBUG] threads "loop threads" completed OK
mtnormalise: [DEBUG] unmapping file "wm_fod.mif"
mtnormalise: [DEBUG] image "wm_fod.mif" unloaded
mtnormalise: [INFO] opening image "gm_scalar.mif"...
mtnormalise: [DEBUG] reading key/value file "gm_scalar.mif"...
mtnormalise: [DEBUG] sanitising image information...
mtnormalise: [INFO] image "gm_scalar.mif" opened with dimensions 145x174x145x1, voxel spacing 1.25x1.25x1.25x1, datatype Float32LE                                                                                          
mtnormalise: [DEBUG] memory-mapping file "gm_scalar.mif"...
mtnormalise: [DEBUG] file "gm_scalar.mif" mapped at 0x7efc67508000, size 14633400 (read-only)
mtnormalise: [DEBUG] image "gm_scalar.mif" loaded
mtnormalise: [DEBUG] image "gm_scalar.mif" initialised with strides = [ -1 145 25230 145 ], start = 144, using direct IO
mtnormalise: [DEBUG] initialising threads...
mtnormalise: [DEBUG] launching 28 threads "loop threads"...
mtnormalise: [DEBUG] waiting for completion of threads "loop threads"...
mtnormalise: [DEBUG] threads "loop threads" completed OK
mtnormalise: [DEBUG] unmapping file "gm_scalar.mif"
mtnormalise: [DEBUG] image "gm_scalar.mif" unloaded
mtnormalise: [INFO] opening image "csf_scalar.mif"...
mtnormalise: [DEBUG] reading key/value file "csf_scalar.mif"...
mtnormalise: [DEBUG] sanitising image information...
mtnormalise: [INFO] image "csf_scalar.mif" opened with dimensions 145x174x145x1, voxel spacing 1.25x1.25x1.25x1, datatype Float32LE
mtnormalise: [DEBUG] memory-mapping file "csf_scalar.mif"...
mtnormalise: [DEBUG] file "csf_scalar.mif" mapped at 0x7efc67503000, size 14633400 (read-only)
mtnormalise: [DEBUG] image "csf_scalar.mif" loaded
mtnormalise: [DEBUG] image "csf_scalar.mif" initialised with strides = [ -1 145 25230 145 ], start = 144, using direct IO
mtnormalise: [DEBUG] initialising threads...
mtnormalise: [DEBUG] launching 28 threads "loop threads"...
mtnormalise: [DEBUG] waiting for completion of threads "loop threads"...
mtnormalise: [DEBUG] threads "loop threads" completed OK
mtnormalise: [DEBUG] unmapping file "csf_scalar.mif"
mtnormalise: [DEBUG] image "csf_scalar.mif" unloaded
mtnormalise: [INFO] initialising basis...
mtnormalise: [DEBUG] initialising threads...
mtnormalise: [DEBUG] launching 28 threads "loop threads"...
mtnormalise: [DEBUG] waiting for completion of threads "loop threads"...
mtnormalise: [DEBUG] threads "loop threads" completed OK
mtnormalise: [INFO]   outlier rejection quartiles: [ -inf -inf ]
mtnormalise: [INFO] Iteration: 1
mtnormalise: [DEBUG] Balance and outlier rejection iteration 1 starts.
mtnormalise: [100%] performing log-domain intensity normalisation
mtnormalise: [DEBUG] deleting scratch buffer for image "index"...
mtnormalise: [DEBUG] image "index" unloaded
mtnormalise: [ERROR] Non-positive tissue balance factor was computed. Balance factors: -nan -nan -nan

I think there’s clearly an issue here:

It looks like it hasn’t performed the first iteration yet, and already the outlier detection has gone funny. I suspect the handling of non-finite values might need to be updated…

Can I also confirm which version of mtnormalise you’re running? Use the mtnormalise -version command to find out.

Cheers,
Donald.

Yes this is the version:

== mtnormalise 3.0.2 ==

This has been an issue on only 4 subjects out of 1065 so it’s a bit strange.

Thanks for your help,

Stefanie

Hi,

I was wondering if you got a chance to update the handling of non-finite values in mtnormalise?

Best,

Stefanie

OK, I had a quick look this morning, and it looks like a simple fix. We’ll hopefully be able to merge this to master within the next few hours.

The basic problem is that there are (I expect) non-finite values in your data for voxels that are included in your mask. So the simplest fix while you’re waiting is simply to make sure such voxels are not included in your mask. How you do this will depend on how you generated the mask in the first place though…

Hi,
Thank you for the great toolbox!
I am pretty new at DTI, and I am trying to use mrtrix3. Everything seems to work great, but I am getting this error : mtnormalise: [ERROR] Non-positive tissue balance factor was computed. Balance factors: -nan -nan -nan
I have checked out and used jdtournier branch from github, with the fix, and I am getting the same error (even with a binary mask created with the fsl “bet -m” command) and I am not sure why…I am wondering if there are any new suggestions on this issue?
Thank you very much!
Milly

Hi Milly,

If you’ve tried code that includes the fix (and are confident that you are in fact invoking the version of the command compiled with the updated code and not some other version of the same command on your system), and are still encountering that error message, but are not sure how to experiment with the data to try to diagnose the source of the problem, then making some example data available to us so that we can replicate the issue would be the best approach.

Cheers
Rob