|
6 | 6 | # @Author: oesteban - [email protected]
|
7 | 7 | # @Date: 2014-06-02 12:06:50
|
8 | 8 | # @Last Modified by: oesteban
|
9 |
| -# @Last Modified time: 2014-06-02 15:22:47 |
| 9 | +# @Last Modified time: 2014-06-03 14:17:08 |
10 | 10 | """The :py:mod:`nipype.interfaces.elastix` provides the interface to
|
11 | 11 | the elastix registration software.
|
12 | 12 |
|
|
22 | 22 | TraitedSpec, File, traits, InputMultiPath)
|
23 | 23 |
|
24 | 24 |
|
| 25 | +from base import ElastixBaseInputSpec |
| 26 | + |
25 | 27 | from ... import logging
|
26 | 28 | logger = logging.getLogger('interface')
|
27 | 29 |
|
28 | 30 |
|
29 |
| -class RegistrationInputSpec(CommandLineInputSpec): |
| 31 | +class RegistrationInputSpec(ElastixBaseInputSpec): |
30 | 32 | fixed_image = File(exists=True, mandatory=True, argstr='-f %s',
|
31 | 33 | desc='fixed image')
|
32 | 34 | moving_image = File(exists=True, mandatory=True, argstr='-m %s',
|
33 | 35 | desc='moving image')
|
34 | 36 |
|
35 |
| - output_path = traits.Directory('./', exists=True, mandatory=True, usedefault=True, |
36 |
| - argstr='-out %s', desc='output directory') |
37 |
| - |
38 | 37 | parameters = InputMultiPath(File(exists=True), mandatory=True, argstr='-p %s...',
|
39 | 38 | desc='parameter file, elastix handles 1 or more -p')
|
40 | 39 |
|
41 | 40 | fixed_mask = File(exists=True, argstr='-fMask %s', desc='mask for fixed image')
|
42 | 41 | moving_mask = File(exists=True, argstr='-mMask %s', desc='mask for moving image')
|
43 | 42 | initial_transform = File(exists=True, argstr='-t0 %s',
|
44 | 43 | 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') |
47 | 44 |
|
48 | 45 |
|
49 | 46 | class RegistrationOutputSpec(TraitedSpec):
|
50 | 47 | transform = InputMultiPath(File(exists=True), desc='output transform')
|
51 | 48 | 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')) |
54 | 51 | warped_files_flags = traits.List(traits.Bool(False),
|
55 | 52 | desc='flag indicating if warped image was generated')
|
56 | 53 |
|
@@ -131,3 +128,40 @@ def _cast(self,val):
|
131 | 128 | return float(val)
|
132 | 129 | except ValueError:
|
133 | 130 | 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