@@ -228,7 +228,7 @@ class RegistrationInputSpec(ANTSCommandInputSpec):
228
228
traits .Bool (argstr = '%s' ), default = True , usedefault = True )
229
229
interpolation = traits .Enum (
230
230
'Linear' , 'NearestNeighbor' , 'CosineWindowedSinc' , 'WelchWindowedSinc' ,
231
- 'HammingWindowedSinc' , 'LanczosWindowedSinc' ,
231
+ 'HammingWindowedSinc' , 'LanczosWindowedSinc' , 'BSpline' ,
232
232
# 'MultiLabel',
233
233
# 'Gaussian',
234
234
# 'BSpline',
@@ -273,8 +273,9 @@ class RegistrationInputSpec(ANTSCommandInputSpec):
273
273
"transform" , usedefault = True , argstr = "%s" , desc = "" )
274
274
output_warped_image = traits .Either (
275
275
traits .Bool , File (), hash_files = False , desc = "" )
276
- output_inverse_warped_image = traits .Either (traits .Bool , File (
277
- ), hash_files = False , requires = ['output_warped_image' ], desc = "" )
276
+ output_inverse_warped_image = traits .Either (traits .Bool , File (),
277
+ hash_files = False ,
278
+ requires = ['output_warped_image' ], desc = "" )
278
279
winsorize_upper_quantile = traits .Range (low = 0.0 , high = 1.0 , value = 1.0 , argstr = '%s' , usedefault = True , desc = "The Upper quantile to clip image ranges" )
279
280
winsorize_lower_quantile = traits .Range (low = 0.0 , high = 1.0 , value = 0.0 , argstr = '%s' , usedefault = True , desc = "The Lower quantile to clip image ranges" )
280
281
collapse_linear_transforms_to_fixed_image_header = traits .Bool (
@@ -293,6 +294,8 @@ class RegistrationOutputSpec(TraitedSpec):
293
294
composite_transform = traits .List (File (exists = True ), desc = 'Composite transform file' )
294
295
inverse_composite_transform = traits .List (
295
296
File (exists = True ), desc = 'Inverse composite transform file' )
297
+ warped_image = File (desc = "Outputs warped image" )
298
+ inverse_warped_image = File (desc = "Outputs the inverse of the warped image" )
296
299
297
300
298
301
class Registration (ANTSCommand ):
@@ -409,6 +412,27 @@ def _formatRegistration(self):
409
412
def _antsJoinList (self , antsList ):
410
413
return "x" .join ([str (i ) for i in antsList ])
411
414
415
+ def _get_outputfilenames (self , inverse = False ):
416
+ output_filename = None
417
+ if not inverse :
418
+ if isdefined (self .inputs .output_warped_image ) and \
419
+ self .inputs .output_warped_image :
420
+ output_filename = self .inputs .output_warped_image
421
+ if isinstance (output_filename , bool ):
422
+ output_filename = '%s_Warped.nii.gz' % self .inputs .output_transform_prefix
423
+ else :
424
+ output_filename = os .path .abspath (output_filename )
425
+ return output_filename
426
+ inv_output_filename = None
427
+ if isdefined (self .inputs .output_inverse_warped_image ) and \
428
+ self .inputs .output_inverse_warped_image :
429
+ inv_output_filename = self .inputs .output_inverse_warped_image
430
+ if isinstance (inv_output_filename , bool ):
431
+ inv_output_filename = '%s_InverseWarped.nii.gz' % self .inputs .output_transform_prefix
432
+ else :
433
+ inv_output_filename = os .path .abspath (inv_output_filename )
434
+ return inv_output_filename
435
+
412
436
def _formatConvergence (self , ii ):
413
437
convergence_iter = self ._antsJoinList (
414
438
self .inputs .number_of_iterations [ii ])
@@ -450,10 +474,15 @@ def _format_arg(self, opt, spec, val):
450
474
# TODO: handle multilabel, gaussian, and bspline options
451
475
return '--interpolation %s' % self .inputs .interpolation
452
476
elif opt == 'output_transform_prefix' :
453
- if isdefined (self .inputs .output_inverse_warped_image ) and self .inputs .output_inverse_warped_image :
454
- return '--output [ %s, %s, %s ]' % (self .inputs .output_transform_prefix , self .inputs .output_warped_image , self .inputs .output_inverse_warped_image )
455
- elif isdefined (self .inputs .output_warped_image ) and self .inputs .output_warped_image :
456
- return '--output [ %s, %s ]' % (self .inputs .output_transform_prefix , self .inputs .output_warped_image )
477
+ out_filename = self ._get_outputfilenames (inverse = False )
478
+ inv_out_filename = self ._get_outputfilenames (inverse = True )
479
+ if out_filename and inv_out_filename :
480
+ return '--output [ %s, %s, %s ]' % (self .inputs .output_transform_prefix ,
481
+ out_filename ,
482
+ inv_out_filename )
483
+ elif out_filename :
484
+ return '--output [ %s, %s ]' % (self .inputs .output_transform_prefix ,
485
+ out_filename )
457
486
else :
458
487
return '--output %s' % self .inputs .output_transform_prefix
459
488
elif opt == 'winsorize_upper_quantile' or opt == 'winsorize_lower_quantile' :
@@ -541,4 +570,10 @@ def _list_outputs(self):
541
570
'InverseComposite.h5'
542
571
outputs ['inverse_composite_transform' ] = [
543
572
os .path .abspath (fileName )]
573
+ out_filename = self ._get_outputfilenames (inverse = False )
574
+ inv_out_filename = self ._get_outputfilenames (inverse = True )
575
+ if out_filename :
576
+ outputs ['warped_image' ] = out_filename
577
+ if inv_out_filename :
578
+ outputs ['inverse_warped_image' ] = inv_out_filename
544
579
return outputs
0 commit comments