Skip to content

Commit a453b8b

Browse files
committed
Merge pull request #1176 from BRAINSia/FixMultiModalAntsRegistration
BUG: Registration interface failed multi-modal
2 parents 335c7a1 + 6df0427 commit a453b8b

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Next release
22
============
33

4+
* BUG: ANTs Registration interface failed with multi-modal inputs
5+
(https://github.com/nipy/nipype/pull/1176) (https://github.com/nipy/nipype/issues/1175)
46
* FIX: Bug in XFibres5 (https://github.com/nipy/nipype/pull/1168)
57
* ENH: Attempt to use hard links for data sink.
68
(https://github.com/nipy/nipype/pull/1161)

nipype/interfaces/ants/registration.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ class Registration(ANTSCommand):
446446
>>> reg5.inputs.sampling_strategy = ['Random', None] # use default strategy in second stage
447447
>>> reg5.inputs.sampling_percentage = [0.05, [0.05, 0.10]]
448448
>>> reg5.cmdline
449-
'antsRegistration --collapse-output-transforms 0 --dimensionality 3 --initial-moving-transform [ trans.mat, 1 ] --initialize-transforms-per-stage 0 --interpolation Linear --output [ output_, output_warped_image.nii.gz ] --restore-state trans.mat --save-state trans.mat --transform Affine[ 2.0 ] --metric CC[ fixed1.nii, moving1.nii, 1, 4, Random, 0.05 ] --convergence [ 1500x200, 1e-08, 20 ] --smoothing-sigmas 1.0x0.0vox --shrink-factors 2x1 --use-estimate-learning-rate-once 1 --use-histogram-matching 1 --transform SyN[ 0.25, 3.0, 0.0 ] --metric CC[ fixed1.nii, moving1.nii, 0.5, 32, None, 0.05 ] --metric Mattes[ fixed1.nii, moving1.nii, 0.5, 32, None, 0.1 ] --convergence [ 100x50x30, 1e-09, 20 ] --smoothing-sigmas 2.0x1.0x0.0vox --shrink-factors 3x2x1 --use-estimate-learning-rate-once 1 --use-histogram-matching 1 --winsorize-image-intensities [ 0.0, 1.0 ] --write-composite-transform 1'
449+
'antsRegistration --collapse-output-transforms 0 --dimensionality 3 --initial-moving-transform [ trans.mat, 1 ] --initialize-transforms-per-stage 0 --interpolation Linear --output [ output_, output_warped_image.nii.gz ] --restore-state trans.mat --save-state trans.mat --transform Affine[ 2.0 ] --metric CC[ fixed1.nii, moving1.nii, 1, 4, Random, 0.05 ] --convergence [ 1500x200, 1e-08, 20 ] --smoothing-sigmas 1.0x0.0vox --shrink-factors 2x1 --use-estimate-learning-rate-once 1 --use-histogram-matching 1 --transform SyN[ 0.25, 3.0, 0.0 ] --metric CC[ fixed1.nii, moving1.nii, 0.5, 32, None, 0.05 ] --metric Mattes[ fixed2.nii, moving2.nii, 0.5, 32, None, 0.1 ] --convergence [ 100x50x30, 1e-09, 20 ] --smoothing-sigmas 2.0x1.0x0.0vox --shrink-factors 3x2x1 --use-estimate-learning-rate-once 1 --use-histogram-matching 1 --winsorize-image-intensities [ 0.0, 1.0 ] --write-composite-transform 1'
450450
"""
451451
DEF_SAMPLING_STRATEGY = 'None'
452452
"""The default sampling strategy argument."""
@@ -466,14 +466,12 @@ def _formatMetric(self, index):
466466
----------
467467
index: the stage index
468468
"""
469-
# The common fixed image.
470-
fixed = self.inputs.fixed_image[0]
471-
# The common moving image.
472-
moving = self.inputs.moving_image[0]
473469
# The metric name input for the current stage.
474470
name_input = self.inputs.metric[index]
475471
# The stage-specific input dictionary.
476472
stage_inputs = dict(
473+
fixed_image=self.inputs.fixed_image[0],
474+
moving_image=self.inputs.moving_image[0],
477475
metric=name_input,
478476
weight=self.inputs.metric_weight[index],
479477
radius_or_bins=self.inputs.radius_or_number_of_bins[index],
@@ -502,16 +500,32 @@ def _formatMetric(self, index):
502500
# dict-comprehension only works with python 2.7 and up
503501
#specs = [{k: v[i] for k, v in items} for i in indexes]
504502
specs = [dict([(k, v[i]) for k, v in items]) for i in indexes]
503+
specs = list()
504+
for i in indexes:
505+
temp = dict([(k, v[i]) for k, v in items])
506+
if i > len( self.inputs.fixed_image ):
507+
temp["fixed_image"] = self.inputs.fixed_image[0]
508+
else:
509+
temp["fixed_image"] = self.inputs.fixed_image[i]
510+
511+
if i > len( self.inputs.moving_image ):
512+
temp["moving_image"] = self.inputs.moving_image[0]
513+
else:
514+
temp["moving_image"] = self.inputs.moving_image[i]
515+
516+
specs.append( temp )
505517
else:
506518
specs = [stage_inputs]
507519

508520
# Format the --metric command line metric arguments, one per
509521
# specification.
510-
return [self._formatMetricArgument(fixed, moving, **spec) for spec in specs]
522+
return [self._formatMetricArgument(**spec) for spec in specs]
511523

512-
def _formatMetricArgument(self, fixed, moving, **kwargs):
524+
def _formatMetricArgument(self, **kwargs):
513525
retval = '%s[ %s, %s, %g, %d' % (kwargs['metric'],
514-
fixed, moving, kwargs['weight'],
526+
kwargs['fixed_image'],
527+
kwargs['moving_image'],
528+
kwargs['weight'],
515529
kwargs['radius_or_bins'])
516530

517531
# The optional sampling strategy.

0 commit comments

Comments
 (0)