@@ -329,3 +329,74 @@ def _list_outputs(self):
329
329
outputs ['output_image' ] = os .path .abspath (
330
330
self ._gen_filename ('output_image' ))
331
331
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