|
11 | 11 | from builtins import range, str
|
12 | 12 | import os
|
13 | 13 |
|
| 14 | +from ...utils.filemanip import filename_to_list |
14 | 15 | from ..base import TraitedSpec, File, Str, traits, InputMultiPath, isdefined
|
15 | 16 | from .base import ANTSCommand, ANTSCommandInputSpec
|
16 | 17 |
|
@@ -219,12 +220,22 @@ class RegistrationInputSpec(ANTSCommandInputSpec):
|
219 | 220 | usedefault=True, desc='image dimension (2 or 3)')
|
220 | 221 | fixed_image = InputMultiPath(File(exists=True), mandatory=True,
|
221 | 222 | 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') |
| 223 | + fixed_image_mask = File( |
| 224 | + exists=True, argstr='%s', max_ver='2.1.0', xor=['fixed_image_masks'], |
| 225 | + desc='mask used to limit metric sampling region of the fixed image') |
| 226 | + fixed_image_masks = InputMultiPath( |
| 227 | + traits.Either('NULL', File(exists=True)), min_ver='2.2.0', xor=['fixed_image_mask'], |
| 228 | + desc='mask used to limit metric sampling region of the fixed image ' |
| 229 | + '(Use "NULL" to omit a mask at a given stage)') |
224 | 230 | moving_image = InputMultiPath(File(exists=True), mandatory=True,
|
225 | 231 | 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') |
| 232 | + moving_image_mask = File( |
| 233 | + exists=True, requires=['fixed_image_mask'], max_ver='2.1.0', xor=['moving_image_masks'], |
| 234 | + desc='mask used to limit metric sampling region of the moving image') |
| 235 | + moving_image_masks = InputMultiPath( |
| 236 | + traits.Either('NULL', File(exists=True)), min_ver='2.2.0', xor=['moving_image_mask'], |
| 237 | + desc='mask used to limit metric sampling region of the moving image ' |
| 238 | + '(Use "NULL" to omit a mask at a given stage)') |
228 | 239 |
|
229 | 240 | save_state = File(argstr='--save-state %s', exists=False,
|
230 | 241 | desc='Filename for saving the internal restorable state of the registration')
|
@@ -648,6 +659,20 @@ class Registration(ANTSCommand):
|
648 | 659 | --metric Mattes[ fixed1.nii, moving1.nii, 1, 32 ] --convergence [ 100x50x30, 1e-09, 20 ] \
|
649 | 660 | --smoothing-sigmas 2.0x1.0x0.0vox --shrink-factors 3x2x1 --use-estimate-learning-rate-once 1 \
|
650 | 661 | --use-histogram-matching 1 --winsorize-image-intensities [ 0.0, 1.0 ] --write-composite-transform 1'
|
| 662 | +
|
| 663 | + >>> # Test masking |
| 664 | + >>> reg9 = copy.deepcopy(reg) |
| 665 | + >>> reg9.inputs.fixed_image_masks = ['NULL', 'fixed1.nii'] |
| 666 | + >>> reg9.cmdline # doctest: +ALLOW_UNICODE |
| 667 | + 'antsRegistration --collapse-output-transforms 0 --dimensionality 3 --initial-moving-transform [ trans.mat, 1 ] \ |
| 668 | +--initialize-transforms-per-stage 0 --interpolation Linear --output [ output_, output_warped_image.nii.gz ] \ |
| 669 | +--transform Affine[ 2.0 ] --metric Mattes[ fixed1.nii, moving1.nii, 1, 32, Random, 0.05 ] \ |
| 670 | +--convergence [ 1500x200, 1e-08, 20 ] --smoothing-sigmas 1.0x0.0vox --shrink-factors 2x1 \ |
| 671 | +--use-estimate-learning-rate-once 1 --use-histogram-matching 1 --masks [ NULL, NULL ] \ |
| 672 | +--transform SyN[ 0.25, 3.0, 0.0 ] --metric Mattes[ fixed1.nii, moving1.nii, 1, 32 ] \ |
| 673 | +--convergence [ 100x50x30, 1e-09, 20 ] --smoothing-sigmas 2.0x1.0x0.0vox --shrink-factors 3x2x1 \ |
| 674 | +--use-estimate-learning-rate-once 1 --use-histogram-matching 1 --masks [ fixed1.nii, NULL ] \ |
| 675 | +--winsorize-image-intensities [ 0.0, 1.0 ] --write-composite-transform 1' |
651 | 676 | """
|
652 | 677 | DEF_SAMPLING_STRATEGY = 'None'
|
653 | 678 | """The default sampling strategy argument."""
|
@@ -783,6 +808,20 @@ def _format_registration(self):
|
783 | 808 | if isdefined(self.inputs.restrict_deformation):
|
784 | 809 | retval.append('--restrict-deformation %s' %
|
785 | 810 | self._format_xarray(self.inputs.restrict_deformation[ii]))
|
| 811 | + if any((isdefined(self.inputs.fixed_image_masks), |
| 812 | + isdefined(self.inputs.moving_image_masks))): |
| 813 | + if isdefined(self.inputs.fixed_image_masks): |
| 814 | + fixed_masks = filename_to_list(self.inputs.fixed_image_masks) |
| 815 | + fixed_mask = fixed_masks[ii if len(fixed_masks) > 1 else 0] |
| 816 | + else: |
| 817 | + fixed_mask = 'NULL' |
| 818 | + |
| 819 | + if isdefined(self.inputs.moving_image_masks): |
| 820 | + moving_masks = filename_to_list(self.inputs.moving_image_masks) |
| 821 | + moving_mask = moving_masks[ii if len(moving_masks) > 1 else 0] |
| 822 | + else: |
| 823 | + moving_mask = 'NULL' |
| 824 | + retval.append('--masks [ %s, %s ]' % (fixed_mask, moving_mask)) |
786 | 825 | return " ".join(retval)
|
787 | 826 |
|
788 | 827 | def _get_outputfilenames(self, inverse=False):
|
|
0 commit comments