@@ -219,12 +219,16 @@ class RegistrationInputSpec(ANTSCommandInputSpec):
219219 usedefault = True , desc = 'image dimension (2 or 3)' )
220220 fixed_image = InputMultiPath (File (exists = True ), mandatory = True ,
221221 desc = 'image to apply transformation to (generally a coregistered functional)' )
222- fixed_image_mask = File (argstr = '%s' , exists = True ,
223- desc = 'mask used to limit metric sampling region of the fixed image' )
222+ fixed_image_mask = InputMultiPath (
223+ traits .Either ('NULL' , File (exists = True )),
224+ desc = 'mask used to limit metric sampling region of the fixed image '
225+ '(Use "NULL" to omit a mask at a given stage)' )
224226 moving_image = InputMultiPath (File (exists = True ), mandatory = True ,
225227 desc = 'image to apply transformation to (generally a coregistered functional)' )
226- moving_image_mask = File (requires = ['fixed_image_mask' ],
227- exists = True , desc = 'mask used to limit metric sampling region of the moving image' )
228+ moving_image_mask = InputMultiPath (
229+ traits .Either ('NULL' , File (exists = True )),
230+ desc = 'mask used to limit metric sampling region of the moving image '
231+ '(Use "NULL" to omit a mask at a given stage)' )
228232
229233 save_state = File (argstr = '--save-state %s' , exists = False ,
230234 desc = 'Filename for saving the internal restorable state of the registration' )
@@ -783,6 +787,20 @@ def _format_registration(self):
783787 if isdefined (self .inputs .restrict_deformation ):
784788 retval .append ('--restrict-deformation %s' %
785789 self ._format_xarray (self .inputs .restrict_deformation [ii ]))
790+ if any ((isdefined (self .inputs .fixed_image_mask ),
791+ isdefined (self .inputs .moving_image_mask ))):
792+ if isdefined (self .inputs .fixed_image_mask ):
793+ fixed_masks = filename_to_list (self .inputs .fixed_image_mask )
794+ fixed_mask = fixed_mask [ii if len (fixed_masks ) > 1 else 0 ]
795+ else :
796+ fixed_mask = 'NULL'
797+
798+ if isdefined (self .inputs .moving_image_mask ):
799+ moving_masks = filename_to_list (self .inputs .moving_image_mask )
800+ moving_mask = moving_mask [ii if len (moving_masks ) > 1 else 0 ]
801+ else :
802+ moving_mask = 'NULL'
803+ retval .append ('--masks [ %s, %s ]' % (fixed_mask , moving_mask ))
786804 return " " .join (retval )
787805
788806 def _get_outputfilenames (self , inverse = False ):
@@ -827,13 +845,7 @@ def _format_winsorize_image_intensities(self):
827845 self .inputs .winsorize_upper_quantile )
828846
829847 def _format_arg (self , opt , spec , val ):
830- if opt == 'fixed_image_mask' :
831- if isdefined (self .inputs .moving_image_mask ):
832- return '--masks [ %s, %s ]' % (self .inputs .fixed_image_mask ,
833- self .inputs .moving_image_mask )
834- else :
835- return '--masks %s' % self .inputs .fixed_image_mask
836- elif opt == 'transforms' :
848+ if opt == 'transforms' :
837849 return self ._format_registration ()
838850 elif opt == 'initial_moving_transform' :
839851 do_invert_transform = self .inputs .invert_initial_moving_transform \
0 commit comments