Skip to content

Commit fed10b4

Browse files
authored
Merge pull request #97 from OpenGATE/gaussian
Add gaussian filter before resampling
2 parents d7ad872 + 998b943 commit fed10b4

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

gatetools/affine_transform.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import logging
1717
logger=logging.getLogger(__name__)
1818

19-
def applyTransformation(input=None, like=None, spacinglike=None, matrix=None, newsize=None, neworigin=None, newspacing=None, newdirection=None, force_resample=None, keep_original_canvas=None, adaptive=None, rotation=None, rotation_center=None, translation=None, pad=None, interpolation_mode=None, bspline_order=2):
19+
def applyTransformation(input=None, like=None, spacinglike=None, matrix=None, newsize=None, neworigin=None, newspacing=None, newdirection=None, force_resample=None, keep_original_canvas=None, adaptive=None, rotation=None, rotation_center=None, translation=None, pad=None, interpolation_mode=None, bspline_order=2, gaussian=False):
2020

2121
if like is not None and spacinglike is not None:
2222
logger.error("Choose between like and spacinglike options")
@@ -77,6 +77,10 @@ def applyTransformation(input=None, like=None, spacinglike=None, matrix=None, ne
7777
if interpolation_mode is None:
7878
interpolation_mode : "linear"
7979

80+
if gaussian:
81+
oldspacing = input.GetSpacing()
82+
input = gt.gaussFilter(input, sigma_mm=0.5*oldspacing/newspacing, float=True)
83+
8084
if not force_resample and not keep_original_canvas:
8185
if neworigin is None:
8286
neworigin = input.GetOrigin()

gatetools/bin/gt_affine_transform.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ def convertNewParameterToFloat(newParameterString, size):
6464
@click.option('--interpolation_mode', '-im', help='Interpolation mode: NN for nearest neighbor, linear for linear interpolation and BSpline for BSpline interpolation', default='linear', type=click.Choice(['NN', 'linear', 'BSpline']))
6565
@click.option('--bspline_order', '-bo', help='For BSpline interpolator, set the interpolation bspline order', default='2', type=click.Choice(['0', '1', '2', '3', '4', '5']))
6666

67+
@click.option('--gaussian', '-g', help='Run a gaussian filter before the downsampling', default='False', is_flag=True))
68+
6769
@gt.add_options(gt.common_options)
68-
def gt_affine_transform_main(input, output, newsize, neworigin, newspacing, newdirection, like, spacinglike, force_resample, keep_original_canvas, adaptive, matrix, rotation, center, translation, pad, interpolation_mode, bspline_order, **kwargs):
70+
def gt_affine_transform_main(input, output, newsize, neworigin, newspacing, newdirection, like, spacinglike, force_resample, keep_original_canvas, adaptive, matrix, rotation, center, translation, pad, interpolation_mode, bspline_order, gaussian, **kwargs):
6971
'''
7072
Basic affine transfomation and resampling of images
7173
@@ -91,6 +93,9 @@ def gt_affine_transform_main(input, output, newsize, neworigin, newspacing, newd
9193
9294
--adaptive flag (in combination with force_resample flag) allows the users to set the newspacing (or spacinglike) and the newsize is automatically computed and vice versa.
9395
96+
--gaussian run a gaussian filter before the downsampling. The sigma is set to 0.5s in mm with s the ratio of the old resolution by the new resolution.
97+
https://dsp.stackexchange.com/a/76015
98+
9499
'''
95100

96101
# logger
@@ -144,7 +149,7 @@ def gt_affine_transform_main(input, output, newsize, neworigin, newspacing, newd
144149
sys.exit(1)
145150
matrixParameter = itk.matrix_from_array(np.array(readMatrix))
146151

147-
outputImage = gt.applyTransformation(inputImage, likeImage, spacingLikeImage, matrixParameter, newsize = itkSize, neworigin = itkOrigin, newspacing = itkSpacing, newdirection = itkDirection, force_resample = force_resample, keep_original_canvas = keep_original_canvas, adaptive = adaptive, rotation = rotationParameter, rotation_center = rotationCenterParameter, translation = translationParameter, pad = pad, interpolation_mode = interpolation_mode, bspline_order=int(bspline_order))
152+
outputImage = gt.applyTransformation(inputImage, likeImage, spacingLikeImage, matrixParameter, newsize = itkSize, neworigin = itkOrigin, newspacing = itkSpacing, newdirection = itkDirection, force_resample = force_resample, keep_original_canvas = keep_original_canvas, adaptive = adaptive, rotation = rotationParameter, rotation_center = rotationCenterParameter, translation = translationParameter, pad = pad, interpolation_mode = interpolation_mode, bspline_order=int(bspline_order), gaussian=gaussian)
148153

149154
itk.imwrite(outputImage, output)
150155

0 commit comments

Comments
 (0)