# ITKv5 N4BiasFieldCorrection regression

**URL:** <https://discourse.itk.org/t/itkv5-n4biasfieldcorrection-regression/579>\
**Category:** Engineering\
**Tags:** itkv5, simpleitk\
**Created:** [January 9, 2018, 7:42pm UTC](https://discourse.itk.org/t/itkv5-n4biasfieldcorrection-regression/579 "2018-01-09T19:42:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [January 9, 2018, 7:42pm UTC](https://discourse.itk.org/t/itkv5-n4biasfieldcorrection-regression/579/1 "2018-01-09T19:42:21Z")

</div>

I have noticed on the SimpleITK dashboard compiled against ITKv5, master, the N4BiasFieldCorrectionImageFilter test failing:

[https://open.cdash.org/testDetails.php?test=616394668&build=5213037](https://open.cdash.org/testDetails.php?test=616394668&build=5213037)

The parameters used are printed in the testing output.

Reverting the recent changes of the module seem to resolve the problem:  
git checkout v4.13.0 Modules/Filtering/BiasCorrection/

Which seems to narrow it down to the following [change in just the filters file](https://github.com/InsightSoftwareConsortium/ITK/commit/5c84e6e6b4768e596439c9879d86f51fa4bda51a#diff-cd59def6ebaefd1d763d4ddda7891621).

SimpleITK is compiled with `ITK_LEGACY_REMOVE` enabled.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [January 9, 2018, 9:36pm UTC](https://discourse.itk.org/t/itkv5-n4biasfieldcorrection-regression/579/2 "2018-01-09T21:36:07Z")

</div>

Does that test use mask? That seems to be deprecated now. Where is the source code of the test?

---

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [January 10, 2018, 2:28pm UTC](https://discourse.itk.org/t/itkv5-n4biasfieldcorrection-regression/579/3 "2018-01-10T14:28:01Z")

</div>

You are correct it is likely due to change in behavior of the Mask.

The code for the SimpleITK test is automatically generated from the JSON description here:

> <https://github.com/SimpleITK/SimpleITK/blob/next/Code/BasicFilters/json/N4BiasFieldCorrectionImageFilter.json#L99-L105>

The test does use a mask image with multiple values, I would presume that the selection of the “masked” pixels would be the pixels with non-zero values. This is likely the point that has changed in the filter, ITK is not consistent with how a mask is defined or used. That is some times a mask is, maskImage[] != 0, while others it is makeImage[]==maskValue.

EDIT: This mask behavior is exactly what has changed. The “UseMaskLabel” ivar is what is controls the behavior between the two mask behaviors above. The default ITK is with m\_UseMaskLable=true, but when ITK\_LEGACY\_REMOVE is defined the behavior is abruptly changed so that m\_UseMaskLabel is removed, and the “false” behavior is used.

It looks like the change in the depreciation did not update the documentation, so the behavior is not correctly described. Still looking into it…

---

<div class="post-metadata">

**Author:** ![hjmjohnson](https://discourse.itk.org/user_avatar/discourse.itk.org/hjmjohnson/32/23_2.png) [@hjmjohnson](https://discourse.itk.org/u/hjmjohnson)\
**Post date:** [January 15, 2018, 6:26pm UTC](https://discourse.itk.org/t/itkv5-n4biasfieldcorrection-regression/579/4 "2018-01-15T18:26:00Z")

</div>

Brad,

Thank you for looking into this. Have you tracked down the change of behavior? Do we need to fix this in ITK?

Thanks,  
Hans

---

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [January 16, 2018, 2:08pm UTC](https://discourse.itk.org/t/itkv5-n4biasfieldcorrection-regression/579/5 "2018-01-16T14:08:34Z")

</div>

Hans,

This was tracked down a change of behavior defined by the default “UseMaskLabel=true” to “UseMakeLabel=false” when ITK\_LEGACY\_REMOVE is enabled. What I find difficult is that at the same time the default value is changed, the flag which controls the behavior is also removed.

I am considering proposing a patch which for ITK\_LEGACY\_REMOVE keeps the UseMaskLabel to the new behavior of “false”, but doesn’t remove the flag until “ITK\_FUTURE\_LEGACY\_REMOVE”. What do you think of that?

---

<div class="post-metadata">

**Author:** ![hjmjohnson](https://discourse.itk.org/user_avatar/discourse.itk.org/hjmjohnson/32/23_2.png) [@hjmjohnson](https://discourse.itk.org/u/hjmjohnson)\
**Post date:** [January 16, 2018, 2:44pm UTC](https://discourse.itk.org/t/itkv5-n4biasfieldcorrection-regression/579/6 "2018-01-16T14:44:04Z")

</div>

Perhaps keep the flag forever.
