Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion gatetools/affine_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import logging
logger=logging.getLogger(__name__)

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):
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):

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

if gaussian:
oldspacing = input.GetSpacing()
input = gt.gaussFilter(input, sigma_mm=0.5*oldspacing/newspacing, float=True)

if not force_resample and not keep_original_canvas:
if neworigin is None:
neworigin = input.GetOrigin()
Expand Down
9 changes: 7 additions & 2 deletions gatetools/bin/gt_affine_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ def convertNewParameterToFloat(newParameterString, size):
@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']))
@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']))

@click.option('--gaussian', '-g', help='Run a gaussian filter before the downsampling', default='False', is_flag=True))

@gt.add_options(gt.common_options)
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):
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):
'''
Basic affine transfomation and resampling of images

Expand All @@ -91,6 +93,9 @@ def gt_affine_transform_main(input, output, newsize, neworigin, newspacing, newd

--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.

--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.
https://dsp.stackexchange.com/a/76015

'''

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

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))
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)

itk.imwrite(outputImage, output)

Expand Down