Skip to content

Commit 361d297

Browse files
committed
ENH: Enable per-stage masking in ants.Registration
1 parent e02cb4a commit 361d297

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

nipype/interfaces/ants/registration.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,14 @@ 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')
224225
moving_image = InputMultiPath(File(exists=True), mandatory=True,
225226
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')
227+
moving_image_mask = InputMultiPath(
228+
traits.Either('NULL', File(exists=True)),
229+
desc='mask used to limit metric sampling region of the moving image')
228230

229231
save_state = File(argstr='--save-state %s', exists=False,
230232
desc='Filename for saving the internal restorable state of the registration')
@@ -783,6 +785,20 @@ def _format_registration(self):
783785
if isdefined(self.inputs.restrict_deformation):
784786
retval.append('--restrict-deformation %s' %
785787
self._format_xarray(self.inputs.restrict_deformation[ii]))
788+
if any((isdefined(self.inputs.fixed_image_mask),
789+
isdefined(self.inputs.moving_image_mask))):
790+
if isdefined(self.inputs.fixed_image_mask):
791+
fixed_masks = filename_to_list(self.inputs.fixed_image_mask)
792+
fixed_mask = fixed_mask[ii if len(fixed_masks) > 1 else 0]
793+
else:
794+
fixed_mask = 'NULL'
795+
796+
if isdefined(self.inputs.moving_image_mask):
797+
moving_masks = filename_to_list(self.inputs.moving_image_mask)
798+
moving_mask = moving_mask[ii if len(moving_masks) > 1 else 0]
799+
else:
800+
moving_mask = 'NULL'
801+
retval.append('--masks [ %s, %s ]' % (fixed_mask, moving_mask]))
786802
return " ".join(retval)
787803

788804
def _get_outputfilenames(self, inverse=False):
@@ -827,13 +843,7 @@ def _format_winsorize_image_intensities(self):
827843
self.inputs.winsorize_upper_quantile)
828844

829845
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':
846+
if opt == 'transforms':
837847
return self._format_registration()
838848
elif opt == 'initial_moving_transform':
839849
do_invert_transform = self.inputs.invert_initial_moving_transform \

nipype/interfaces/ants/tests/test_auto_Registration.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ def test_Registration_inputs():
2323
),
2424
fixed_image=dict(mandatory=True,
2525
),
26-
fixed_image_mask=dict(argstr='%s',
27-
),
26+
fixed_image_mask=dict(),
2827
float=dict(argstr='--float %d',
2928
),
3029
ignore_exception=dict(nohash=True,
@@ -58,8 +57,7 @@ def test_Registration_inputs():
5857
metric_weight_stage_trait=dict(),
5958
moving_image=dict(mandatory=True,
6059
),
61-
moving_image_mask=dict(requires=['fixed_image_mask'],
62-
),
60+
moving_image_mask=dict(),
6361
num_threads=dict(nohash=True,
6462
usedefault=True,
6563
),

0 commit comments

Comments
 (0)