Error running dwibiascorrect (ZeroDivisionError) after dwifslpreproc

Hi all, I’ve been following the single-tissue CSD tutorial on Mrtrix3 readthedocs. I finished running dwifslpreproc on a subject with rpe_all, and I am now trying to run dwibiascorrect on the output of dwifslpreproc (“dwi_preprocessed_fixed.mif”). However when I run dwibiascorrect with ANTS, I get this error:

dwiextract in.mif - -bzero | mrmath - mean mean_bzero.mif -axis 3
Command:  mrconvert mean_bzero.mif mean_bzero.nii -strides +1,+2,+3
Command:  mrconvert mask.mif mask.nii -strides +1,+2,+3
Command:  N4BiasFieldCorrection -d 3 -i mean_bzero.nii -w mask.nii -o [corrected.nii,init_bias.nii] -s 4 -b [100,3] -c [1000,0.0]
Command:  mrcalc mean_bzero.mif mask.mif -mult - | mrmath - sum - -axis 0 | mrmath - sum - -axis 1 | mrmath - sum - -axis 2 | mrdump -
Command:  mrcalc corrected.nii mask.mif -mult - | mrmath - sum - -axis 0 | mrmath - sum - -axis 1 | mrmath - sum - -axis 2 | mrdump -
Traceback (most recent call last):
  File "/cvmfs/soft.computecanada.ca/easybuild/software/2017/avx2/Compiler/intel2016.4/mrtrix/3.0_RC3/bin/dwibiascorrect", line 138, in <module>
    run.command('mrcalc ' + init_bias_path + ' ' + str(output_integral / input_integral) + ' -mult ' + bias_path)
ZeroDivisionError: float division by zero.

I also tried with the FSL option, but I get another error:

dwibiascorrect -fsl dwi_preprocessed.mif dwi_preprocessed_unbiased.mif
dwibiascorrect:
dwibiascorrect: Note that this script makes use of commands / algorithms that have relevant articles for citation; INCLUDING FROM EXTERNAL SOFTWARE PACKAGES. Please consult the help page (-help option) for more information.
dwibiascorrect:
dwibiascorrect: [WARNING] Use of -fsl option in dwibiascorrect script is discouraged due to its strong dependence on initial brain masking, and its inability to correct voxels outside of this mask.Use of the -ants option is recommended for quantitative DWI analyses.
dwibiascorrect: Generated temporary directory: /scratch/ahan/hcpa/HCA6000030_V1_MR/dwibiascorrect-tmp-THH2R7/
Command:  mrconvert /scratch/ahan/hcpa/HCA6000030_V1_MR/dwi_preprocessed.mif /scratch/ahan/hcpa/HCA6000030_V1_MR/dwibiascorrect-tmp-THH2R7/in.mif
dwibiascorrect: Changing to temporary directory (/scratch/ahan/hcpa/HCA6000030_V1_MR/dwibiascorrect-tmp-THH2R7/)
Command:  dwi2mask in.mif mask.mif
Command:  dwiextract in.mif - -bzero | mrmath - mean mean_bzero.mif -axis 3
Command:  mrcalc mean_bzero.mif mask.mif -mult - | mrconvert - mean_bzero_masked.nii -strides -1,+2,+3
Command:  fast -t 2 -o fast -n 3 -b mean_bzero_masked.nii
dwibiascorrect:
dwibiascorrect: [ERROR] Command failed: fast -t 2 -o fast -n 3 -b mean_bzero_masked.nii 

Any help is greatly appreciated!

Hi Ana,

The division-by-zero error produced when using dwibiascorrect ants implies that, when the mean b=0 image is multiplied by the brain mask, and all voxel intensities within the image are then added together, the result is precisely 0.0. The most likely cause of this would be if the brain mask itself does not contain any voxels. If you ran dwibiascorrect ants without the -mask option, then the script itself runs the dwi2mask command internally. So I would suggest running dwi2mask on your data and checking the output; if it is indeed empty, then you will need to use some other approach to derive a brain mask.

(Good bias field correction depends on a good mask, but deriving a brain mask can fail if there’s a strong bias field…)

Regarding dwibiascorrect fsl, over and above the warning it issues, the terminal output is cropped without providing the requisite debugging information, but if I had to guess I’d say it’s the same fundamental issue: the generated brain mask is empty, multiplication of the mean b=0 image with this mask results in an image that contains all zeroes, and so the FSL command fast fails.

Cheers
Rob

Thanks Rob! It turned out that some of the files were corrupt; the mask wasn’t working. I redid dwi2mask and everything works fine! Thanks!