N4 Bias Field Correction

Hello All,
I want to apply bias field correction in 3D T1w MR volumes(including non-brain sections too). Images are in NIfTI format. Though it is recommended to use masks, I don’t have masks or atlas for the data.
I saw the documentation here, N4 Bias Field Correction — SimpleITK 2.0rc2 documentation
and ran the following codes:

input = sitk.ReadImage(files[0])
image = sitk.Cast(input, sitk.sitkFloat32)
# print(type(image))
correctedImg = sitk.N4BiasFieldCorrection(image)
sitk.WriteImage(correctedImg, outfile) # outfile is just string variable or path

But the output comes totally blank. What am I missing?

Edit: I got the bias corrected image in MNI format. Is there a way to get the images in native MR space?

Hello @banikr,

Not sure what is the format of ‘outfile’, so it could be an issue there. Possibly try looking at the images before writing to disk:

import SimpleITK as sitk

image = sitk.ReadImage(files[0], sitk.sitkFloat32)
sitk.Show(image, 'original image')
sitk.Show(sitk.N4BiasFieldCorrection(image), 'corrected image')

When writing, SimpleITK infers the format based on the file extension. Saving a float image in an ‘sitk.sitkUInt8’ format will lead to unexpected results.

Hi @zivy
The codes worked and perform bias field correction.
image image
Are there ways to varify that the bias field correction actually worked?
Is it performing bias field correction in just the brain part or whole head? I needed the whole head bias correction.

In the main image, the intensity ranged from 0~499,
in the corrected image I see an intensity range: 0~489.8
Apart from that, there are no significant changes.

N.B. outfile is just the path of the corrected image.

Hello @banikr,

If you did not provide a mask then it uses the whole image for computing the bias field. As you are actually only interested in the head, you likely can use simple thresholding, possibly try Otsu to define the head mask:

mask = sitk.OtsuThreshold(image,0,1)

and provide the mask as input to the bias field correction. Don’t forget to check that the mask actually segments the head.

To verify that the correction actually works you can evaluate it with a reasonably large dataset, see this TCIA collection.

1 Like