@@ -243,17 +243,15 @@ class ApplyTransformsInputSpec(ANTSCommandInputSpec):
243243 'Gaussian' ,
244244 'BSpline' ,
245245 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+ )
250250 transforms = InputMultiPath (
251251 File (exists = True ), argstr = '%s' , mandatory = True , desc = 'transform files' )
252252 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" ],
257255 desc = 'output a composite warp file instead of a transformed image' )
258256
259257
@@ -280,7 +278,23 @@ class ApplyTransforms(ANTSCommand):
280278 >>> at.inputs.invert_transform_flags = [False, False]
281279 >>> at.cmdline
282280 '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 ]'
284298
285299
286300 """
@@ -304,7 +318,7 @@ def _get_transform_filenames(self):
304318 if len (self .inputs .transforms ) == len (self .inputs .invert_transform_flags ):
305319 invert_code = 1 if self .inputs .invert_transform_flags [
306320 ii ] else 0
307- retval .append ("--transform [%s,%d ]" %
321+ retval .append ("--transform [ %s, %d ]" %
308322 (self .inputs .transforms [ii ], invert_code ))
309323 else :
310324 raise Exception (("ERROR: The useInverse list must have the same number "
@@ -315,7 +329,8 @@ def _get_transform_filenames(self):
315329
316330 def _get_output_warped_filename (self ):
317331 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 ))
319334 else :
320335 return "--output %s" % (self ._gen_filename ("output_image" ))
321336
@@ -325,8 +340,13 @@ def _format_arg(self, opt, spec, val):
325340 elif opt == "transforms" :
326341 return self ._get_transform_filenames ()
327342 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
330350 return super (ApplyTransforms , self )._format_arg (opt , spec , val )
331351
332352 def _list_outputs (self ):
@@ -381,7 +401,7 @@ class ApplyTransformsToPoints(ANTSCommand):
381401 >>> at.inputs.invert_transform_flags = [False, False]
382402 >>> at.cmdline
383403 '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 ]'
385405
386406
387407 """
@@ -396,7 +416,7 @@ def _get_transform_filenames(self):
396416 if len (self .inputs .transforms ) == len (self .inputs .invert_transform_flags ):
397417 invert_code = 1 if self .inputs .invert_transform_flags [
398418 ii ] else 0
399- retval .append ("--transform [%s,%d ]" %
419+ retval .append ("--transform [ %s, %d ]" %
400420 (self .inputs .transforms [ii ], invert_code ))
401421 else :
402422 raise Exception (("ERROR: The useInverse list must have the same number "
0 commit comments