Skip to content

Commit 38b2e6f

Browse files
committed
New interface ApplyWarp using transformix
1 parent 2fa7a5b commit 38b2e6f

File tree

3 files changed

+66
-11
lines changed

3 files changed

+66
-11
lines changed

nipype/interfaces/elastix/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# @Author: oesteban - [email protected]
77
# @Date: 2014-06-02 12:06:07
88
# @Last Modified by: oesteban
9-
# @Last Modified time: 2014-06-02 12:40:10
9+
# @Last Modified time: 2014-06-03 14:06:18
1010
"""Top-level namespace for elastix."""
1111

12-
from registration import Registration
12+
from registration import Registration, ApplyWarp

nipype/interfaces/elastix/base.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
4+
# vi: set ft=python sts=4 ts=4 sw=4 et:
5+
#
6+
# @Author: oesteban - [email protected]
7+
# @Date: 2014-06-03 13:42:46
8+
# @Last Modified by: oesteban
9+
# @Last Modified time: 2014-06-03 13:43:50
10+
11+
from ..base import (CommandLine, CommandLineInputSpec, isdefined,
12+
TraitedSpec, File, traits, InputMultiPath)
13+
from ... import logging
14+
logger = logging.getLogger('interface')
15+
16+
17+
class ElastixBaseInputSpec(CommandLineInputSpec):
18+
output_path = traits.Directory('./', exists=True, mandatory=True, usedefault=True,
19+
argstr='-out %s', desc='output directory')
20+
num_threads = traits.Int(1, argstr='-threads %01d',
21+
desc='set the maximum number of threads of elastix')

nipype/interfaces/elastix/registration.py

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# @Author: oesteban - [email protected]
77
# @Date: 2014-06-02 12:06:50
88
# @Last Modified by: oesteban
9-
# @Last Modified time: 2014-06-02 15:22:47
9+
# @Last Modified time: 2014-06-03 14:17:08
1010
"""The :py:mod:`nipype.interfaces.elastix` provides the interface to
1111
the elastix registration software.
1212
@@ -22,35 +22,32 @@
2222
TraitedSpec, File, traits, InputMultiPath)
2323

2424

25+
from base import ElastixBaseInputSpec
26+
2527
from ... import logging
2628
logger = logging.getLogger('interface')
2729

2830

29-
class RegistrationInputSpec(CommandLineInputSpec):
31+
class RegistrationInputSpec(ElastixBaseInputSpec):
3032
fixed_image = File(exists=True, mandatory=True, argstr='-f %s',
3133
desc='fixed image')
3234
moving_image = File(exists=True, mandatory=True, argstr='-m %s',
3335
desc='moving image')
3436

35-
output_path = traits.Directory('./', exists=True, mandatory=True, usedefault=True,
36-
argstr='-out %s', desc='output directory')
37-
3837
parameters = InputMultiPath(File(exists=True), mandatory=True, argstr='-p %s...',
3938
desc='parameter file, elastix handles 1 or more -p')
4039

4140
fixed_mask = File(exists=True, argstr='-fMask %s', desc='mask for fixed image')
4241
moving_mask = File(exists=True, argstr='-mMask %s', desc='mask for moving image')
4342
initial_transform = File(exists=True, argstr='-t0 %s',
4443
desc='parameter file for initial transform')
45-
num_threads = traits.Int(1, argstr='-threads %01d',
46-
desc='set the maximum number of threads of elastix')
4744

4845

4946
class RegistrationOutputSpec(TraitedSpec):
5047
transform = InputMultiPath(File(exists=True), desc='output transform')
5148
warped_file = File(desc='input moving image warped to fixed image')
52-
warped_files = InputMultiPath(File(), desc=('input moving image warped to'
53-
' fixed image at each level'))
49+
warped_files = InputMultiPath(File(exists=False),
50+
desc=('input moving image warped to fixed image at each level'))
5451
warped_files_flags = traits.List(traits.Bool(False),
5552
desc='flag indicating if warped image was generated')
5653

@@ -131,3 +128,40 @@ def _cast(self,val):
131128
return float(val)
132129
except ValueError:
133130
return val
131+
132+
class ApplyWarpInputSpec(ElastixBaseInputSpec):
133+
transform_file = File(exists=True, mandatory=True, argstr='-tp %s',
134+
desc='transform-parameter file, only 1')
135+
136+
moving_image = File(exists=True, argstr='-in %s', mandatory=True,
137+
desc='input image to deform')
138+
139+
140+
141+
class ApplyWarpOutputSpec(TraitedSpec):
142+
warped_file = File(desc='input moving image warped to fixed image')
143+
144+
class ApplyWarp(CommandLine):
145+
"""Use `transformix` to apply a transform on an input image.
146+
The transform is specified in the transform-parameter file.
147+
148+
Example::
149+
150+
>>> from nipype.interfaces.elastix import ApplyWarp
151+
>>> reg = ApplyWarp()
152+
>>> reg.inputs.moving_image = 'moving1.nii'
153+
>>> reg.inputs.transform_file = 'TransformParameters.0.txt'
154+
>>> reg.cmdline
155+
'transformix -in moving1.nii -out ./ -tp TransformParameters.0.txt'
156+
"""
157+
158+
_cmd = 'transformix'
159+
input_spec = ApplyWarpInputSpec
160+
output_spec = ApplyWarpOutputSpec
161+
162+
def _list_outputs(self):
163+
outputs = self._outputs().get()
164+
out_dir = op.abspath(self.inputs.output_path)
165+
outputs['out_file'] = op.join(out_dir,'result.nii.gz')
166+
return outputs
167+

0 commit comments

Comments
 (0)