Skip to content

Commit 56f4fe1

Browse files
committed
Added ApplyTransformsToPoints interface
1 parent a281843 commit 56f4fe1

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

nipype/interfaces/ants/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .registration import ANTS, Registration
88

99
# Resampling Programs
10-
from resampling import ApplyTransforms, WarpImageMultiTransform, WarpTimeSeriesImageMultiTransform
10+
from .resampling import ApplyTransforms, ApplyTransformsToPoints, WarpImageMultiTransform, WarpTimeSeriesImageMultiTransform
1111

1212

1313
# Segmentation Programs

nipype/interfaces/ants/resampling.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,74 @@ def _list_outputs(self):
329329
outputs['output_image'] = os.path.abspath(
330330
self._gen_filename('output_image'))
331331
return outputs
332+
333+
334+
class ApplyTransformsToPointsInputSpec(ANTSCommandInputSpec):
335+
dimension = traits.Enum(2, 3, 4, argstr='--dimensionality %d',
336+
desc=('This option forces the image to be treated '
337+
'as a specified-dimensional image. If not '
338+
'specified, antsWarp tries to infer the '
339+
'dimensionality from the input image.'))
340+
input_file = File(argstr='--input %s', mandatory=True,
341+
desc=('image to apply transformation to (generally a '
342+
'coregistered functional)'),
343+
exists=True)
344+
output_file = traits.Str(argstr='--output %s',
345+
desc=('output file name'), name_source=['input_file'],
346+
hash_files=False, name_template='%s_transformed.csv')
347+
transforms = traits.List(
348+
File(exists=True), argstr='%s', mandatory=True, desc=(''))
349+
invert_transform_flags = traits.List(traits.Bool())
350+
351+
352+
class ApplyTransformsToPointsOutputSpec(TraitedSpec):
353+
output_file = File(exists=True, desc='csv file with transformed coordinates')
354+
355+
356+
class ApplyTransformsToPoints(ANTSCommand):
357+
"""ApplyTransforms, applied to an input image, transforms it according to a
358+
reference image and a transform (or a set of transforms).
359+
360+
Examples
361+
--------
362+
363+
>>> from nipype.interfaces.ants import ApplyTransforms
364+
>>> at = ApplyTransforms()
365+
>>> at.inputs.dimension = 3
366+
>>> at.inputs.input_image = 'moving1.nii'
367+
>>> at.inputs.reference_image = 'fixed1.nii'
368+
>>> at.inputs.output_image = 'deformed_moving1.nii'
369+
>>> at.inputs.interpolation = 'Linear'
370+
>>> at.inputs.default_value = 0
371+
>>> at.inputs.transforms = ['trans.mat', 'ants_Warp.nii.gz']
372+
>>> at.inputs.invert_transform_flags = [False, False]
373+
>>> at.cmdline
374+
'antsApplyTransforms --default-value 0 --dimensionality 3 --input moving1.nii --interpolation Linear --output deformed_moving1.nii --reference-image fixed1.nii --transform [trans.mat,0] --transform [ants_Warp.nii.gz,0]'
375+
376+
377+
"""
378+
_cmd = 'antsApplyTransformsToPoints'
379+
input_spec = ApplyTransformsToPointsInputSpec
380+
output_spec = ApplyTransformsToPointsOutputSpec
381+
382+
383+
def _getTransformFileNames(self):
384+
retval = []
385+
for ii in range(len(self.inputs.transforms)):
386+
if isdefined(self.inputs.invert_transform_flags):
387+
if len(self.inputs.transforms) == len(self.inputs.invert_transform_flags):
388+
invert_code = 1 if self.inputs.invert_transform_flags[
389+
ii] else 0
390+
retval.append("--transform [%s,%d]" %
391+
(self.inputs.transforms[ii], invert_code))
392+
else:
393+
raise Exception("ERROR: The useInverse list must have the same number of entries as the transformsFileName list.")
394+
else:
395+
retval.append("--transform %s" % self.inputs.transforms[ii])
396+
return " ".join(retval)
397+
398+
def _format_arg(self, opt, spec, val):
399+
if opt == "transforms":
400+
return self._getTransformFileNames()
401+
return super(ApplyTransformsToPoints, self)._format_arg(opt, spec, val)
402+

0 commit comments

Comments
 (0)