Dwibiascorrect doesn't do a good job


#1

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?

Thanks,
Mahmoud


dwibiascorrect_ANTs_error
#2

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.


#3

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?

Thanks,
Mahmoud


#4

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?


#5

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.


#6

Younger than 6 months.


#7

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


#8

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:
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] 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:
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:
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?


#9

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
(/home/zeydabadi/mz/data//FOD/dwibiascorrect-tmp-Y9T7M5/)
, 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.