From 87dd10908e63af658de29931eb7edfd188fd88bb Mon Sep 17 00:00:00 2001 From: Philip Cook Date: Tue, 25 Apr 2023 12:42:46 -0400 Subject: [PATCH] ENH: default n3 / n4 spline mesh size of 1 More general than a fixed spacing --- ants/utils/bias_correction.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ants/utils/bias_correction.py b/ants/utils/bias_correction.py index 5c6ca730..904318cf 100644 --- a/ants/utils/bias_correction.py +++ b/ants/utils/bias_correction.py @@ -46,7 +46,7 @@ def n3_bias_field_correction2( rescale_intensities=False, shrink_factor=4, convergence={"iters": 50, "tol": 1e-7}, - spline_param=200, + spline_param=None, number_of_fitting_levels=4, return_bias_field=False, verbose=False, @@ -84,7 +84,7 @@ def n3_bias_field_correction2( spline_param : float or vector Parameter controlling number of control points in spline. Either single value, indicating the spacing in each direction, or vector with one entry per dimension of image, indicating - the mesh size. + the mesh size. If None, defaults to mesh size of 1 in all dimensions. number_of_fitting_levels : integer Number of fitting levels per iteration. @@ -113,6 +113,8 @@ def n3_bias_field_correction2( tol = convergence["tol"] if mask is None: mask = get_mask(image) + if spline_param is None: + spline_param = [1] * image.dimension N3_CONVERGENCE_1 = "[%i,%.10f]" % (iters, tol) N3_SHRINK_FACTOR_1 = str(shrink_factor) @@ -164,7 +166,7 @@ def n4_bias_field_correction( rescale_intensities=False, shrink_factor=4, convergence={"iters": [50, 50, 50, 50], "tol": 1e-7}, - spline_param=200, + spline_param=None, return_bias_field=False, verbose=False, weight_mask=None, @@ -201,7 +203,8 @@ def n4_bias_field_correction( spline_param : float or vector Parameter controlling number of control points in spline. Either single value, indicating the spacing in each direction, or vector with one entry per - dimension of image, indicating the mesh size. + dimension of image, indicating the mesh size. If None, defaults to mesh size of 1 in all + dimensions. return_bias_field : boolean Return bias field instead of bias corrected image. @@ -227,6 +230,8 @@ def n4_bias_field_correction( tol = convergence["tol"] if mask is None: mask = get_mask(image) + if spline_param is None: + spline_param = [1] * image.dimension N4_CONVERGENCE_1 = "[%s, %.10f]" % ("x".join([str(it) for it in iters]), tol) N4_SHRINK_FACTOR_1 = str(shrink_factor)