@@ -243,17 +243,15 @@ class ApplyTransformsInputSpec(ANTSCommandInputSpec):
243
243
'Gaussian' ,
244
244
'BSpline' ,
245
245
argstr = '%s' , usedefault = True )
246
- # TODO: Implement these options for multilabel, gaussian, and bspline
247
- # interpolation_sigma = traits.Float(requires=['interpolation'] )
248
- # interpolation_alpha = traits.Float(requires=['interpolation_sigma'] )
249
- # bspline_order = traits.Int(3, requires=['interpolation'] )
246
+ interpolation_parameters = traits . Either ( traits . Tuple ( traits . Int ()), # BSpline (order)
247
+ traits .Tuple ( traits . Float (), # Gaussian/MultiLabel (sigma, alpha )
248
+ traits .Float () )
249
+ )
250
250
transforms = InputMultiPath (
251
251
File (exists = True ), argstr = '%s' , mandatory = True , desc = 'transform files' )
252
252
invert_transform_flags = InputMultiPath (traits .Bool ())
253
- default_value = traits .Float (
254
- 0.0 , argstr = '--default-value %g' , usedefault = True )
255
- # TODO: Change to boolean
256
- print_out_composite_warp_file = traits .Enum (0 , 1 , requires = ["output_image" ],
253
+ default_value = traits .Float (0.0 , argstr = '--default-value %g' , usedefault = True )
254
+ print_out_composite_warp_file = traits .Bool (False , requires = ["output_image" ],
257
255
desc = 'output a composite warp file instead of a transformed image' )
258
256
259
257
@@ -280,7 +278,23 @@ class ApplyTransforms(ANTSCommand):
280
278
>>> at.inputs.invert_transform_flags = [False, False]
281
279
>>> at.cmdline
282
280
'antsApplyTransforms --default-value 0 --dimensionality 3 --input moving1.nii --interpolation Linear \
283
- --output deformed_moving1.nii --reference-image fixed1.nii --transform [trans.mat,0] --transform [ants_Warp.nii.gz,0]'
281
+ --output deformed_moving1.nii --reference-image fixed1.nii --transform [ trans.mat, 0 ] \
282
+ --transform [ ants_Warp.nii.gz, 0 ]'
283
+
284
+ >>> at1 = ApplyTransforms()
285
+ >>> at1.inputs.dimension = 3
286
+ >>> at1.inputs.input_image = 'moving1.nii'
287
+ >>> at1.inputs.reference_image = 'fixed1.nii'
288
+ >>> at1.inputs.output_image = 'deformed_moving1.nii'
289
+ >>> at1.inputs.interpolation = 'BSpline'
290
+ >>> at1.inputs.interpolation_parameters = (5,)
291
+ >>> at1.inputs.default_value = 0
292
+ >>> at1.inputs.transforms = ['trans.mat', 'ants_Warp.nii.gz']
293
+ >>> at1.inputs.invert_transform_flags = [False, False]
294
+ >>> at1.cmdline
295
+ 'antsApplyTransforms --default-value 0 --dimensionality 3 --input moving1.nii --interpolation BSpline[ 5 ] \
296
+ --output deformed_moving1.nii --reference-image fixed1.nii --transform [ trans.mat, 0 ] \
297
+ --transform [ ants_Warp.nii.gz, 0 ]'
284
298
285
299
286
300
"""
@@ -304,7 +318,7 @@ def _get_transform_filenames(self):
304
318
if len (self .inputs .transforms ) == len (self .inputs .invert_transform_flags ):
305
319
invert_code = 1 if self .inputs .invert_transform_flags [
306
320
ii ] else 0
307
- retval .append ("--transform [%s,%d ]" %
321
+ retval .append ("--transform [ %s, %d ]" %
308
322
(self .inputs .transforms [ii ], invert_code ))
309
323
else :
310
324
raise Exception (("ERROR: The useInverse list must have the same number "
@@ -315,7 +329,8 @@ def _get_transform_filenames(self):
315
329
316
330
def _get_output_warped_filename (self ):
317
331
if isdefined (self .inputs .print_out_composite_warp_file ):
318
- return "--output [%s,%s]" % (self ._gen_filename ("output_image" ), self .inputs .print_out_composite_warp_file )
332
+ return "--output [ %s, %d ]" % (self ._gen_filename ("output_image" ),
333
+ int (self .inputs .print_out_composite_warp_file ))
319
334
else :
320
335
return "--output %s" % (self ._gen_filename ("output_image" ))
321
336
@@ -325,8 +340,13 @@ def _format_arg(self, opt, spec, val):
325
340
elif opt == "transforms" :
326
341
return self ._get_transform_filenames ()
327
342
elif opt == 'interpolation' :
328
- # TODO: handle multilabel, gaussian, and bspline options
329
- return '--interpolation %s' % self .inputs .interpolation
343
+ if self .inputs .interpolation in ['BSpline' , 'MultiLabel' , 'Gaussian' ] and \
344
+ isdefined (self .inputs .interpolation_parameters ):
345
+ return '--interpolation %s[ %s ]' % (self .inputs .interpolation ,
346
+ ', ' .join ([str (param )
347
+ for param in self .inputs .interpolation_parameters ]))
348
+ else :
349
+ return '--interpolation %s' % self .inputs .interpolation
330
350
return super (ApplyTransforms , self )._format_arg (opt , spec , val )
331
351
332
352
def _list_outputs (self ):
@@ -381,7 +401,7 @@ class ApplyTransformsToPoints(ANTSCommand):
381
401
>>> at.inputs.invert_transform_flags = [False, False]
382
402
>>> at.cmdline
383
403
'antsApplyTransformsToPoints --dimensionality 3 --input moving.csv --output moving_transformed.csv \
384
- --transform [trans.mat,0 ] --transform [ants_Warp.nii.gz,0 ]'
404
+ --transform [ trans.mat, 0 ] --transform [ ants_Warp.nii.gz, 0 ]'
385
405
386
406
387
407
"""
@@ -396,7 +416,7 @@ def _get_transform_filenames(self):
396
416
if len (self .inputs .transforms ) == len (self .inputs .invert_transform_flags ):
397
417
invert_code = 1 if self .inputs .invert_transform_flags [
398
418
ii ] else 0
399
- retval .append ("--transform [%s,%d ]" %
419
+ retval .append ("--transform [ %s, %d ]" %
400
420
(self .inputs .transforms [ii ], invert_code ))
401
421
else :
402
422
raise Exception (("ERROR: The useInverse list must have the same number "
0 commit comments