# Passing mask argument in N4BiasFieldCorrection()

**URL:** <https://discourse.itk.org/t/passing-mask-argument-in-n4biasfieldcorrection/5793>\
**Category:** Algorithms\
**Tags:** n4biasfield, simpleitk, python\
**Created:** [March 10, 2023, 10:01pm UTC](https://discourse.itk.org/t/passing-mask-argument-in-n4biasfieldcorrection/5793 "2023-03-10T22:01:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Jeong](https://discourse.itk.org/user_avatar/discourse.itk.org/thomas_jeong/32/3317_2.png) [@Thomas\_Jeong](https://discourse.itk.org/u/Thomas_Jeong)\
**Post date:** [March 10, 2023, 10:01pm UTC](https://discourse.itk.org/t/passing-mask-argument-in-n4biasfieldcorrection/5793/1 "2023-03-10T22:01:06Z")

</div>

Hello all,

Trying to use the N4BiasFieldCorrection() method to fix the intensity inhomogeneity in Dixon MRI scans. I have used the function with success just passing the image as the only argument, such as below:

`sitk.N4BiasFieldCorrection(image)`

This was successful but I am trying to run it with my own mask to improve results. Passing the following command has not yielded any success:

```auto
image = sitk.ReadImage(files[0], sitk.sitkFloat32)
mask = sitk.ReadImage(masks[0], sitk.sitkUInt8)
sitk.N4BiasFieldCorrection(image, maskImage=mask)

```

Thanks.

---

<div class="post-metadata">

**Author:** ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)\
**Post date:** [March 10, 2023, 10:55pm UTC](https://discourse.itk.org/t/passing-mask-argument-in-n4biasfieldcorrection/5793/2 "2023-03-10T22:55:54Z")

</div>

Hello @Thomas_Jeong,

Based on the code and description it is hard to guess what the issue could be. Please see if [the example](https://simpleitk.readthedocs.io/en/master/link_N4BiasFieldCorrection_docs.html) and its usage of a mask helps you debug the issue.

---

<div class="post-metadata">

**Author:** ![Thomas\_Jeong](https://discourse.itk.org/user_avatar/discourse.itk.org/thomas_jeong/32/3317_2.png) [@Thomas\_Jeong](https://discourse.itk.org/u/Thomas_Jeong)\
**Post date:** [March 17, 2023, 7:15pm UTC](https://discourse.itk.org/t/passing-mask-argument-in-n4biasfieldcorrection/5793/3 "2023-03-17T19:15:11Z")

</div>

The trouble I have with that method is obtaining an .nrrd file. Additionally, I’m not sure what their mask looks like in that example. Is it the green mask titled ‘Default Mask Image?’ If so, is it important that our mask is green instead of another color?

Best,  
Thomas

---

<div class="post-metadata">

**Author:** ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)\
**Post date:** [March 19, 2023, 11:19pm UTC](https://discourse.itk.org/t/passing-mask-argument-in-n4biasfieldcorrection/5793/4 "2023-03-19T23:19:09Z")

</div>

Hello @Thomas_Jeong,

The mask is just **displayed** in green in the example.

The mask itself is a binary image with ones denoting the foreground and zeros denoting background.
