Passing mask argument in N4BiasFieldCorrection()

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:


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:

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


Hello @Thomas_Jeong,

Based on the code and description it is hard to guess what the issue could be. Please see if the example and its usage of a mask helps you debug the issue.

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?


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.