Skip to content

Commit d38562c

Browse files
author
Shoshana Berleant
committed
allow ANTS ApplyTransforms to use identity transform
1 parent 741405f commit d38562c

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

nipype/interfaces/ants/resampling.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,12 @@ class ApplyTransformsInputSpec(ANTSCommandInputSpec):
247247
traits.Tuple(traits.Float(), # Gaussian/MultiLabel (sigma, alpha)
248248
traits.Float())
249249
)
250-
transforms = InputMultiPath(
251-
File(exists=True), argstr='%s', desc='transform files: will be applied in reverse order. '
252-
'For example, the last specified transform will be applied first; if this input is not '
253-
'set, the identity transform is used')
250+
transforms = traits.Either(InputMultiPath(File(exists=True), desc='transform files: will be '
251+
'applied in reverse order. For example, the last '
252+
'specified transform will be applied first.'),
253+
traits.Enum('identity', desc='use the identity transform'),
254+
mandatory=True,
255+
argstr='%s')
254256
invert_transform_flags = InputMultiPath(traits.Bool())
255257
default_value = traits.Float(0.0, argstr='--default-value %g', usedefault=True)
256258
print_out_composite_warp_file = traits.Bool(False, requires=["output_image"],
@@ -294,12 +296,24 @@ class ApplyTransforms(ANTSCommand):
294296
>>> at1.inputs.default_value = 0
295297
>>> at1.inputs.transforms = ['ants_Warp.nii.gz', 'trans.mat']
296298
>>> at1.inputs.invert_transform_flags = [False, False]
297-
>>> at1.cmdline # doctest: +IGNORE_UNICODE
299+
>>> at1.cmdline
298300
'antsApplyTransforms --default-value 0 --dimensionality 3 --input moving1.nii --interpolation BSpline[ 5 ] \
299301
--output deformed_moving1.nii --reference-image fixed1.nii --transform [ ants_Warp.nii.gz, 0 ] \
300302
--transform [ trans.mat, 0 ]'
301303
302-
304+
>>> atid = ApplyTransforms()
305+
>>> atid.inputs.dimension = 3
306+
>>> atid.inputs.input_image = 'moving1.nii'
307+
>>> atid.inputs.reference_image = 'fixed1.nii'
308+
>>> atid.inputs.output_image = 'deformed_moving1.nii'
309+
>>> atid.inputs.interpolation = 'BSpline'
310+
>>> atid.inputs.interpolation_parameters = (5,)
311+
>>> atid.inputs.default_value = 0
312+
>>> atid.inputs.transforms = 'identity'
313+
>>> atid.cmdline
314+
'antsApplyTransforms --default-value 0 --dimensionality 3 --input moving1.nii \
315+
--interpolation BSpline[ 5 ] --output deformed_moving1.nii --reference-image fixed1.nii \
316+
--transform identity'
303317
"""
304318
_cmd = 'antsApplyTransforms'
305319
input_spec = ApplyTransformsInputSpec
@@ -315,6 +329,9 @@ def _gen_filename(self, name):
315329
return None
316330

317331
def _get_transform_filenames(self):
332+
''' the input transforms may be a list of files or the keyword 'identity' '''
333+
if self.inputs.transforms == 'identity':
334+
return "--transform identity"
318335
retval = []
319336
for ii in range(len(self.inputs.transforms)):
320337
if isdefined(self.inputs.invert_transform_flags):

0 commit comments

Comments
 (0)