Skip to content

preproc_n4

Perform N4 bias field correction on either an anatomical image or a diffusion volume. For diffusion volumes, the module automatically derives the bspline parameter, number of stages, and iteration pyramid based on the image resolution and size. The formula used are as follows: For the BSpline parameter: BSplineParam = 2 ** (NbStages - 1) * NbVoxelsBetweenKnots * ShrinkFactor * ImageResolution For the number of stages in the iteration pyramid: If SmallestDimension ≤ NbVoxelsBetweenKnots * ShrinkFactor: NbStages = 1 Else: NbStages = ceil( log2(SmallestDimension / (NbVoxelsBetweenKnots * ShrinkFactor)) ) For the iteration pyramid: Slope = (MinIter - MaxIter) / (1 - Retain) Intercept = MaxIter - Slope * Retain For i in linspace(0, 1, NbStages): If i < Retain: Iteration = MaxIter Else: Iteration = round(Slope * i + Intercept) The default values for the shrink_factor and nb_voxels_between_knots are set to 4 and 8, respectively, which are suitable for most diffusion and anatomical volumes from a large age range of subjects and species. For a human T1w image of 1 mm isotropic resolution and a size of 193x229x193, a typical N4 call (with automatically derived parameters) would look like this:

N4BiasFieldCorrection -i T1w.nii.gz \
-o [output__image_n4.nii.gz, bias_field.nii.gz] \
-c [1000x1000x850x100, 1e-6] \
-b [256, 3] \
-s 4

For more information on how this formula was derived, please view those references: [1] N4 Wiki: https://github.com/ANTsX/ANTs/wiki/N4BiasFieldCorrection [2] Tustison, N. J., Avants, B. B., Cook, P. A., Zheng, Y., Egan, A., Yushkevich, P. A., & Gee, J. C. (2010). N4ITK: Improved N3 Bias Correction. IEEE Transactions on Medical Imaging, 29(6), 1310–1320. https://doi.org/10.1109/TMI.2010.2046908 [3] Valcourt Caron, A., Shmuel, A., Hao, Z., & Descoteaux, M. (2023). versaFlow: A versatile pipeline for resolution adapted diffusion MRI processing and its application to studying the variability of the PRIME-DE database. Frontiers in Neuroinformatics, Volume 17-2023. https://doi.org/10.3389/fninf.2023.1191200

Keywords : correction, N4, bias field


Format : tuple val(meta), path(image), path(bval), path(bvec), path(mask)

TypeDescriptionMandatoryPattern
metamapGroovy Map containing sample information e.g. [ id:'test', single_end:false ]True
imagefileNifti image file to correctTrue*.{nii,nii.gz}
bvalfileB-value file for the diffusion imageFalse*.bval
bvecfileB-vector file for the diffusion imageFalse*.bvec
maskfileNifti image file mask for the referenceFalse*.{nii,nii.gz}

Format : tuple val(meta), path(*__image_n4.nii.gz)

TypeDescriptionMandatoryPattern
metamapGroovy Map containing sample information e.g. [ id:'test', single_end:false ]True
*__image_n4.nii.gzfileN4 corrected imageTrue*__image_n4.{nii,nii.gz}

Format : path(versions.yml)

TypeDescriptionMandatoryPattern
versions.ymlfileFile containing software versionsTrueversions.yml

TypeDescriptionDefaultChoices
prefixstringPrefix to add to the output file name (e.g. “n4_“)
b0thresholdintegerThreshold for the b0 volume to be used as a mask.10
nb_voxels_between_knotsintegerNumber of voxels between B-spline knots.8
shrink_factorintegerShrink factor for the image resampling.4
maxiterintegerMaximum number of iterations for the N4 algorithm.1000
miniterintegerMinimum number of iterations for the N4 algorithm.100
retainnumberRatio of stages for which the number of iterations is fixed to the maximum iterations defined.0.6

DescriptionDOI
scilpyThe Sherbrooke Connectivity Imaging Lab (SCIL) Python dMRI processing toolbox.


Last updated : 2025-10-30