Dwibiascorrect doesn't do a good job

Hello all,

I used dwibiascorrect with -ant switch on my single shell dwi data but it data looks better without bias correction.
Please see before bias correction:

and this is after:

Any idea what’s going wrong?


This sounds suspiciously like this issue, which seems specific to MRtrix3 version 3.0_RC2. Which version are you using? In 3.0_RC3, the default parameters for the ants algorithm were adjusted, so it might work better in that version. In addition, support was added for overriding them on the command line, which should at least allow you to tweak the parameters to the underlying ANTs command, N4BiasFieldCorrection, to hopefully get a decent result.

1 Like

Thanks for your response.
Here is the version that I use:
MRtrix 3.0_RC3-83-g538f905c dwibiascorrect bin version: 3.0_RC3-83-g538f905c

Also, my data is from an infant cohorts.
Is there any any assumption in the pipeline that the data must be from adults? if so, where can I modify that?


OK, yes there’s a good chance neonatal data might need to be handled slightly differently. There is at least one parameter that springs to mind, assuming you’re using the ANTs algorithm: the b parameter sets the scale in mm. You can adjust that at the dwibiascorrect command-line using the -ants.b parameter. You’ll note its current default is set for the adult human brain, try a lower value, and see if that helps?

1 Like

What age range are we talking about?

Also, looking at your original images, the problem may be that the bias field is a little “too” extreme before, which will result in a sub-optimal brain mask created withing dwibiascorrect, which can in turn result in the “overcorrected” result you got (e.g. if that overly bright region after the “correction” was actually outside the initial mask). What do you get when you run dwi2mask on the data before bias field correction? If you’re able to correct that mask (even manually), you can feed it to the -mask option of dwibiascorrect. Alternatively (and this may sound a bit weird): run dwi2mask on the data before bias field correction, as well as on the data you currently get after bias field correction, and then combine both masks into a single one (via mrcalc), and then run dwibiascorrect again on the original data, but now with the newly obtained mask via the -mask option. This strategy may provide you in a semi-automated way with a more complete mask to feed to dwibiascorrect, potentially without having to resort to manual edits.

1 Like

Younger than 6 months.

Thanks for the hint.
Using the mask option solved the problem. However, I’m not sure whether that’s the optimal result.

Hello all,

I’m having difficulties with dwibiascorrect again.
Based on the advice mentioned above, I’m using brain masks to get better results and in fact, it does not work:

dwibiascorrect -force -ants -mask hifi_nodifupdn_brain_mask.nii.gz eddy_corrected_dataup.nii.gz -fslgrad eddy_corrected_dataup.eddy_rotated_bvecs dataup.bval eddy_bias_corrected_dataup.nii.gz
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: [WARNING] Output file 'eddy_bias_corrected_dataup.nii.gz' already exists; will be overwritten at script completion
dwibiascorrect: Generated temporary directory: /home/zeydabadi/mz/data//FOD/dwibiascorrect-tmp-Y9T7M5/
Command:  mrconvert /home/zeydabadi/mz/data//FOD/eddy_corrected_dataup.nii.gz /home/zeydabadi/mz/data//FOD/dwibiascorrect-tmp-Y9T7M5/in.mif -fslgrad /home/zeydabadi/mz/data//FOD/eddy_corrected_dataup.eddy_rotated_bvecs /home/zeydabadi/mz/data//FOD/dataup.bval
Command:  mrconvert /home/zeydabadi/mz/data//FOD/hifi_nodifupdn_brain_mask.nii.gz /home/zeydabadi/mz/data//FOD/dwibiascorrect-tmp-Y9T7M5/mask.mif
dwibiascorrect: Changing to temporary directory (/home/zeydabadi/mz/data//FOD/dwibiascorrect-tmp-Y9T7M5/)
Command:  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]
dwibiascorrect: [ERROR] Command failed: 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] (dwibiascorrect:130)
dwibiascorrect: Output of failed command:
dwibiascorrect: Changing back to original directory (/home/zeydabadi/mz/data//FOD)
dwibiascorrect: Script failed while executing the 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]
dwibiascorrect: For debugging, inspect contents of temporary directory: /home/zeydabadi/mz/data//FOD/dwibiascorrect-tmp-Y9T7M5/

The input image is a 4D image and mask is a 3D one.
Could someone please elaborate how dwibiascorrection operates?

That’s a critical failure within the N4BiasFieldCorrection command (which is part of ANTs, not MRtrix3). Unfortunately it’s not providing any information at the command-line that the MRtrix3 wrapper script can then echo to you: “Output of failed command:” prints nothing (I’ve since revised this message under such circumstances).

What I would suggest is going into the temporary directory
, and manually running the N4BiasFieldCorrection command, with exactly the parameters being provided to it as printed by dwibiascorrect. At least once in the past I’ve come across a non-MRtrix3 command where the terminal output normally seen when running the command is written in such a way that the wrapping Python script is unable to capture it; so running it manually yourself may provide extra information. You could also see if N4BiasFieldCorrection has any debugging command-line flags of its own that you could exploit.

I have the same issue as @zeydabadi 's last one. I have tried your suggestion @rsmith to directly run N4BiasFieldCorrection as it is displayed in error.txt but no output nor error are generated. Any insight ?

Thanks in advance,

Unfortunately, with absolutely no error message generated, from a non-MRtrix3 command, I really can’t provide any wisdom at all :man_shrugging: Maybe @zeydabadi managed to glean some insight and can share such?

1 Like

Hi, I found this post as I had the same problem in one subject of adults in my data. The advices given by MRtrix developers worked for me. I would like to share with you guys how a similar problem in adult dataset was solved, so it might help others who bump into this problem in future. Basically, a better mask without very bright voxels in the bottom of the brain will eliminate this issue. In the figure attached, the left and right panels showed the preprocessed diffusion weighted images with two masks. The mask in the left panel (red) was created automatically, which includes a few high-intensity voxels in cerebellum. The mask in the right panel (blue) was modified on the basis of the mask used in the left panel. Using the modified mask made a big difference as you can see that the corrected diffusion weighted images had very wired high signal in the left panel but not that severe in the right panel. Hope this helps.