# Dwibiascorrect doesn't do a good job

**URL:** https://community.mrtrix.org/t/dwibiascorrect-doesnt-do-a-good-job/1811
**Category:** Uncategorized
**Created:** [August 2, 2018, 7:43pm UTC](https://community.mrtrix.org/t/dwibiascorrect-doesnt-do-a-good-job/1811 "2018-08-02T19:43:27Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![zeydabadi](https://community.mrtrix.org/user_avatar/community.mrtrix.org/zeydabadi/32/1425_2.png) [@zeydabadi](https://community.mrtrix.org/u/zeydabadi)
#### Post date: [August 2, 2018, 7:43pm UTC](https://community.mrtrix.org/t/dwibiascorrect-doesnt-do-a-good-job/1811/1 "2018-08-02T19:43:27Z")

</div>

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:

 ![before](https://community.mrtrix.org/uploads/default/original/2X/6/6c6294b7da0e0e860facb049e03ea443a195391a.PNG)

and this is after:

 ![after](https://community.mrtrix.org/uploads/default/original/2X/e/e83939b3c7592d119dc7a0a403fb5145ee7d2660.PNG)

Any idea what’s going wrong?

Thanks,  
Mahmoud

---

<div class="post-metadata">

### Author: ![jdtournier](https://community.mrtrix.org/user_avatar/community.mrtrix.org/jdtournier/32/2594_2.png) [@jdtournier](https://community.mrtrix.org/u/jdtournier)
#### Post date: [August 6, 2018, 6:57pm UTC](https://community.mrtrix.org/t/dwibiascorrect-doesnt-do-a-good-job/1811/2 "2018-08-06T18:57:53Z")

</div>

This sounds suspiciously like [this issue](https://community.mrtrix.org/t/dwibiascorrect-with-ants-high-intensity-in-cerebellum-brainstem/1338?u=jdtournier), 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](https://github.com/MRtrix3/mrtrix3/commit/df0ecd528cba733e225807c40b3a78d22416ba72#diff-bd288f9ce77b63b3acf3d4bc5bbeeac4), so it might work better in that version. In addition, [support was added for overriding them on the command line](https://github.com/MRtrix3/mrtrix3/commit/e1720d227115b1ffe2867dbfb94200b524270ce3#diff-bd288f9ce77b63b3acf3d4bc5bbeeac4), which should at least allow you to tweak the parameters to the underlying ANTs command, [N4BiasFieldCorrection](http://manpages.ubuntu.com/manpages/trusty/man1/N4BiasFieldCorrection.1.html), to hopefully get a decent result.

---

<div class="post-metadata">

### Author: ![zeydabadi](https://community.mrtrix.org/user_avatar/community.mrtrix.org/zeydabadi/32/1425_2.png) [@zeydabadi](https://community.mrtrix.org/u/zeydabadi)
#### Post date: [August 20, 2018, 10:57pm UTC](https://community.mrtrix.org/t/dwibiascorrect-doesnt-do-a-good-job/1811/3 "2018-08-20T22:57:07Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jdtournier](https://community.mrtrix.org/user_avatar/community.mrtrix.org/jdtournier/32/2594_2.png) [@jdtournier](https://community.mrtrix.org/u/jdtournier)
#### Post date: [August 21, 2018, 8:12pm UTC](https://community.mrtrix.org/t/dwibiascorrect-doesnt-do-a-good-job/1811/4 "2018-08-21T20:12:40Z")

</div>

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](https://mrtrix.readthedocs.io/en/latest/reference/scripts/dwibiascorrect.html#options-for-ants-n4biasfieldcorrection). You’ll note its current default is set for the adult human brain, try a lower value, and see if that helps?

---

<div class="post-metadata">

### Author: ![ThijsDhollander](https://community.mrtrix.org/user_avatar/community.mrtrix.org/thijsdhollander/32/1617_2.png) [@ThijsDhollander](https://community.mrtrix.org/u/ThijsDhollander)
#### Post date: [August 22, 2018, 2:36am UTC](https://community.mrtrix.org/t/dwibiascorrect-doesnt-do-a-good-job/1811/5 "2018-08-22T02:36:37Z")

</div>

> [@zeydabadi](#):
>
> infant cohorts

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.

---

<div class="post-metadata">

### Author: ![zeydabadi](https://community.mrtrix.org/user_avatar/community.mrtrix.org/zeydabadi/32/1425_2.png) [@zeydabadi](https://community.mrtrix.org/u/zeydabadi)
#### Post date: [August 22, 2018, 5:03pm UTC](https://community.mrtrix.org/t/dwibiascorrect-doesnt-do-a-good-job/1811/6 "2018-08-22T17:03:06Z")

</div>

Younger than 6 months.

---

<div class="post-metadata">

### Author: ![zeydabadi](https://community.mrtrix.org/user_avatar/community.mrtrix.org/zeydabadi/32/1425_2.png) [@zeydabadi](https://community.mrtrix.org/u/zeydabadi)
#### Post date: [August 22, 2018, 8:16pm UTC](https://community.mrtrix.org/t/dwibiascorrect-doesnt-do-a-good-job/1811/7 "2018-08-22T20:16:27Z")

</div>

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

---

<div class="post-metadata">

### Author: ![zeydabadi](https://community.mrtrix.org/user_avatar/community.mrtrix.org/zeydabadi/32/1425_2.png) [@zeydabadi](https://community.mrtrix.org/u/zeydabadi)
#### Post date: [September 3, 2018, 5:24pm UTC](https://community.mrtrix.org/t/dwibiascorrect-doesnt-do-a-good-job/1811/8 "2018-09-03T17:24:52Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![rsmith](https://community.mrtrix.org/user_avatar/community.mrtrix.org/rsmith/32/2672_2.png) [@rsmith](https://community.mrtrix.org/u/rsmith)
#### Post date: [September 5, 2018, 6:34am UTC](https://community.mrtrix.org/t/dwibiascorrect-doesnt-do-a-good-job/1811/9 "2018-09-05T06:34:26Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![kehamza](https://community.mrtrix.org/letter_avatar_proxy/v4/letter/k/49beb7/32.png) [@kehamza](https://community.mrtrix.org/u/kehamza)
#### Post date: [August 6, 2019, 3:41pm UTC](https://community.mrtrix.org/t/dwibiascorrect-doesnt-do-a-good-job/1811/10 "2019-08-06T15:41:05Z")

</div>

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,  
Hamza

---

<div class="post-metadata">

### Author: ![rsmith](https://community.mrtrix.org/user_avatar/community.mrtrix.org/rsmith/32/2672_2.png) [@rsmith](https://community.mrtrix.org/u/rsmith)
#### Post date: [August 18, 2019, 1:20pm UTC](https://community.mrtrix.org/t/dwibiascorrect-doesnt-do-a-good-job/1811/11 "2019-08-18T13:20:56Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Jiaying\_Zhang](https://community.mrtrix.org/user_avatar/community.mrtrix.org/jiaying_zhang/32/3083_2.png) [@Jiaying\_Zhang](https://community.mrtrix.org/u/Jiaying_Zhang)
#### Post date: [November 29, 2021, 9:59am UTC](https://community.mrtrix.org/t/dwibiascorrect-doesnt-do-a-good-job/1811/12 "2021-11-29T09:59:55Z")

</div>

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.

 ![Screen_Shot_2021-11-29_at_17_56_26](https://community.mrtrix.org/uploads/default/original/2X/2/25ceaf14da5a8715c8ba9c8e4a9428d9e3256226.png)
