Behavior N4Biasfieldcorrection
See original GitHub issueI 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…
- First case: default parameters and brain with skull. Results show hole in brain. (attached result), range seems to affect result
- Same brain but skull-stripped. Results seems OK (attached result)
- First case but using ANTs in command line linux. Result is OK
Use of last version of ANTspy from source.
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:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
Thank you @ntustison