ANTs: N4BiasFieldCorrection fails on images with negative values

Describe the bug I’m running N4BiasFieldCorrection as part of fmriprep and it produced strange results on one of my images. The input image looks pretty much fine, but the output image has negative values pretty much everywhere inside the skull except for a ring and a small spot in the cerebellum with values in the 1000s. At the suggestion of @effigies I looked for negative values and found that there were a good number of voxels with values less than -100 with a minimum of -321. I added 500 to the input data and it worked.

To Reproduce Steps to reproduce the behavior:

  1. Download and unzip the data needed to reproduce from here: https://drive.google.com/file/d/1zaZ2Qug3Tt7_I6zQcPRCT5a-1mlTng-P/view?usp=sharing
  2. Run N4BiasFieldCorrection --bspline-fitting [ 200 ] -d 3 --input-image ref_bold_corrected_trans.nii.gz --mask-image tpl-MNI152NLin2009cAsym_res-02_desc-brain_mask_trans_dil_hdr.nii.gz --output ref_bold_corrected_trans_corrected_debug.nii.gz to see the bad normalization result.
  3. Run N4BiasFieldCorrection --bspline-fitting [ 200 ] -d 3 --input-image ref_bold_corrected_trans_embiggen.nii.gz --mask-image tpl-MNI152NLin2009cAsym_res-02_desc-brain_mask_trans_dil_hdr.nii.gz --output ref_bold_corrected_trans_corrected_embiggen_debug.nii.gz to produce the bettter results.

Expected behavior It would be good if this corner case could either be caught and avoided. Alternatively, it could be caught and a warning could be provided.

Screenshots Here’s the input image: Screen Shot 2019-08-26 at 12 25 53 PM

And the mask overlaid on the input image in red: Screen Shot 2019-08-26 at 12 26 03 PM

The results of the bias correction. note the spot in the cerebellum: Screen Shot 2019-08-26 at 12 26 45 PM Screen Shot 2019-08-26 at 12 27 31 PM

Finally, the results after adding 500 to the input image: Screen Shot 2019-08-26 at 12 27 07 PM

Desktop (please complete the following information): This is running inside a singularity container based on the fmriprep v 1.4.1 docker image. Here’s the ANTs version information: ANTs Version: 2.2.0.dev815-g0740f Compiled: Jun 27 2017 17:39:25

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (9 by maintainers)

Most upvoted comments

Just to answer a couple questions:

is N4(image + 500) == N4(image) + 500?

As @Shotgunosine pointed out, this is not true. But doing something like

0) get range of input image = [a,b]
1) rescale input image to be in a positive, e.g., [100,1000]
2) perform N4 on 1)
3) rescale image from 2) to be in [a,b]

would be reasonable although since the MRI scale is not absolute, step 3) would probably not be necessary. One thing about the core of this algorithm which goes back to N3 is that the range of the output could be very different from the range of the input. That’s why we ultimately put in the -r option.

Is there any chance that the registration and transformation could be updated with options to remove the negative values they introduce?

No, this is feature creep which we try to avoid.

My current thought is to make the nonnegativity requirement explicit in the help menu and then throw a warning if there are negative values with the suggestion above included with that warning.

Thanks @Shotgunosine for the detailed description of the problem, and thank you all for the great suggestions.

I totally agree all the issues and recommendations given above pertain to fMRIPrep. I also think that a big warning when N4 finds negative values would be more than useful (and could’ve preemted this issue).

I’m not doing anything extra or special, this is all from within fMRIprep’s workflows. It’s happening because the original BOLD image is transformed and then skull stripping is repeated on the transformed image. N4BiasFieldCorrection is part of the BOLD skull stripping workflow. @oesteban may be able to comment further on how it’s used.

Agree on not changing the registration, which is not just for MRI, or even just for medical images. You could register CT images where negative values are perfectly correct.

I don’t understand why fmirprep wants to run N4 after resampling the image to template space, but doing it beforehand would solve the interpolation problem.

ImageMath’s TruncateImageIntensity command might solve the problem as well as improve robustness to outlier intensities skewing the histogram.

I also notices the default shrink factor is being used, which is 4. With a low-res BOLD image you might be sampling way fewer voxels than you would for a T1. This might also increase susceptibility to outliers.

fMRIprep should be handling this internally, or perhaps using Linear interpolation. But, as I understand, BOLD is not typically corrected for inhomogeneities, and you’re supposed to correct/use the native space BOLD, not the template space images wherever possible.

I wonder whether BSpline has been validated for transforming BOLD without creating interesting effects.

The negative values are likely the result of using BSpline interpolation to compute the deformed image.

I think it would be nice to have in the N4BiasFieldCorrection application a means to deal with negative values as well as winsorize outliers like antsRegistration does.

I think a lot of these issues got handled implicitly in the original N3 nu_correct program, because it converted things to MINC format and in doing so (usually) imposed a sensible range for the histogram.

N4 includes a log transform so this is expected