question-mark

Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Behavior N4Biasfieldcorrection

See original GitHub issue

Issue Description

I have a behavior which is strange using N4Biasfieldcorrection on a brain with skull. As mentionned in another post, i check range of image intensities and rescale to the range [10, 100] then unscaled…

  1. First case: default parameters and brain with skull. Results show hole in brain. (attached result), range seems to affect result
  2. Same brain but skull-stripped. Results seems OK (attached result)
  3. First case but using ANTs in command line linux. Result is OK

Use of last version of ANTspy from source.

Screenshot from 2020-12-02 20-17-27 Screenshot from 2020-12-02 20-17-39

import numpy as np
import ants
from typing import Tuple

def _min_max_scaling(image: np.ndarray, scaling_range: Tuple[int, int] = (10, 100)) -> Tuple[np.ndarray, float, float]:
    image_scaled = np.copy(image).astype(np.float32)
    min_ = (scaling_range[0] - np.min(image)).astype(np.float32)
    scale_ = ((scaling_range[1] - scaling_range[0]) / (np.max(image) - np.min(image))).astype(np.float32)
    image_scaled *= scale_
    image_scaled += min_
    print(np.min(image_scaled))
    return image_scaled, min_, scale_

def _invert_min_max_scaling(image_scaled: np.ndarray, scale_: float, min_: float) -> np.ndarray:
    image_scaled -= min_
    image_scaled /= scale_
    return image_scaled

image = ants.image_read("sample_t1.nii.gz", reorient=True)
image_scaled, min_, scale_ = _min_max_scaling(image.numpy())
image = image.new_image_like(image_scaled)
img_n4 = ants.n4_bias_field_correction(image, verbose=True)

image_unscaled = _invert_min_max_scaling(img_n4.numpy(), scale_, min_)
img_n4 = image.new_image_like(image_unscaled)
ants.image_write(img_n4, "sample_t1_n4.nii.gz")

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ntustisoncommented, Dec 3, 2020

There is no 'right" scaling range just as there is no absolute intensity range in MRI. Just make sure the range is greater than at least 1 as the intensities are log transformed.

0reactions
Alxalinecommented, Dec 4, 2020

Thank you @ntustison

Read more comments on GitHub >

github_iconTop Results From Across the Web

N4ITK: Improved N3 Bias Correction - PMC - NCBI
we have found that this improves convergence behavior over the N3MNI algorithm. We provide further details of both contributions in subsequent sections.
Read more >
bigbigbean/N4BiasFieldCorrection: This is N4 bias ... - GitHub
This is N4 bias field correction for MR image. N4BiasFieldCorrection.py is the code that we should put all the file name and path...
Read more >
N4BiasFieldCorrection - part of ANTS registration suite
N4BiasFieldCorrection N4 is a variant of the popular N3 (nonparameteric nonuniform normalization) retrospective bias correction algorithm.
Read more >
ITKv5 N4BiasFieldCorrection regression - Engineering - ITK
I have noticed on the SimpleITK dashboard compiled against ITKv5, master, the N4BiasFieldCorrectionImageFilter test failing: ...
Read more >
Advanced Normalization Tools ( ANTs ) Discussion
I'm trying to understand why, and prevent this behavior if possible. Here is an example of the command I use: N4BiasFieldCorrection -i ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found