|
1 | 1 | """ANTs' utilities."""
|
2 | 2 | import os
|
3 |
| -from ...utils.imagemanip import copy_header as _copy_header |
4 | 3 | from ..base import traits, isdefined, TraitedSpec, File, Str, InputMultiObject
|
5 |
| -from .base import ANTSCommandInputSpec, ANTSCommand |
| 4 | +from .base import ANTSCommandInputSpec, ANTSCommand, FixHeaderANTSCommand |
6 | 5 |
|
7 | 6 |
|
8 | 7 | class _ImageMathInputSpec(ANTSCommandInputSpec):
|
@@ -68,7 +67,7 @@ class _ImageMathOuputSpec(TraitedSpec):
|
68 | 67 | output_image = File(exists=True, desc="output image file")
|
69 | 68 |
|
70 | 69 |
|
71 |
| -class ImageMath(ANTSCommand): |
| 70 | +class ImageMath(FixHeaderANTSCommand): |
72 | 71 | """
|
73 | 72 | Operations over images.
|
74 | 73 |
|
@@ -98,16 +97,6 @@ class ImageMath(ANTSCommand):
|
98 | 97 | input_spec = _ImageMathInputSpec
|
99 | 98 | output_spec = _ImageMathOuputSpec
|
100 | 99 |
|
101 |
| - def aggregate_outputs(self, runtime=None, needed_outputs=None): |
102 |
| - """Overload the aggregation with header replacement, if required.""" |
103 |
| - outputs = super(ImageMath, self).aggregate_outputs( |
104 |
| - runtime, needed_outputs) |
105 |
| - if self.inputs.copy_header: # Fix headers |
106 |
| - _copy_header( |
107 |
| - self.inputs.op1, outputs["output_image"], keep_dtype=True |
108 |
| - ) |
109 |
| - return outputs |
110 |
| - |
111 | 100 |
|
112 | 101 | class _ResampleImageBySpacingInputSpec(ANTSCommandInputSpec):
|
113 | 102 | dimension = traits.Int(
|
@@ -157,7 +146,7 @@ class _ResampleImageBySpacingOutputSpec(TraitedSpec):
|
157 | 146 | output_image = File(exists=True, desc="resampled file")
|
158 | 147 |
|
159 | 148 |
|
160 |
| -class ResampleImageBySpacing(ANTSCommand): |
| 149 | +class ResampleImageBySpacing(FixHeaderANTSCommand): |
161 | 150 | """
|
162 | 151 | Resample an image with a given spacing.
|
163 | 152 |
|
@@ -203,16 +192,6 @@ def _format_arg(self, name, trait_spec, value):
|
203 | 192 |
|
204 | 193 | return super(ResampleImageBySpacing, self)._format_arg(name, trait_spec, value)
|
205 | 194 |
|
206 |
| - def aggregate_outputs(self, runtime=None, needed_outputs=None): |
207 |
| - """Overload the aggregation with header replacement, if required.""" |
208 |
| - outputs = super(ResampleImageBySpacing, self).aggregate_outputs( |
209 |
| - runtime, needed_outputs) |
210 |
| - if self.inputs.copy_header: # Fix headers |
211 |
| - _copy_header( |
212 |
| - self.inputs.input_image, outputs["output_image"], keep_dtype=True |
213 |
| - ) |
214 |
| - return outputs |
215 |
| - |
216 | 195 |
|
217 | 196 | class _ThresholdImageInputSpec(ANTSCommandInputSpec):
|
218 | 197 | dimension = traits.Int(
|
@@ -269,7 +248,7 @@ class _ThresholdImageOutputSpec(TraitedSpec):
|
269 | 248 | output_image = File(exists=True, desc="resampled file")
|
270 | 249 |
|
271 | 250 |
|
272 |
| -class ThresholdImage(ANTSCommand): |
| 251 | +class ThresholdImage(FixHeaderANTSCommand): |
273 | 252 | """
|
274 | 253 | Apply thresholds on images.
|
275 | 254 |
|
@@ -299,16 +278,6 @@ class ThresholdImage(ANTSCommand):
|
299 | 278 | input_spec = _ThresholdImageInputSpec
|
300 | 279 | output_spec = _ThresholdImageOutputSpec
|
301 | 280 |
|
302 |
| - def aggregate_outputs(self, runtime=None, needed_outputs=None): |
303 |
| - """Overload the aggregation with header replacement, if required.""" |
304 |
| - outputs = super(ThresholdImage, self).aggregate_outputs( |
305 |
| - runtime, needed_outputs) |
306 |
| - if self.inputs.copy_header: # Fix headers |
307 |
| - _copy_header( |
308 |
| - self.inputs.input_image, outputs["output_image"], keep_dtype=True |
309 |
| - ) |
310 |
| - return outputs |
311 |
| - |
312 | 281 |
|
313 | 282 | class _AIInputSpec(ANTSCommandInputSpec):
|
314 | 283 | dimension = traits.Enum(
|
@@ -465,7 +434,7 @@ class AverageAffineTransformInputSpec(ANTSCommandInputSpec):
|
465 | 434 | position=1,
|
466 | 435 | desc="Outputfname.txt: the name of the resulting transform.",
|
467 | 436 | )
|
468 |
| - transforms = InputMultiPath( |
| 437 | + transforms = InputMultiObject( |
469 | 438 | File(exists=True),
|
470 | 439 | argstr="%s",
|
471 | 440 | mandatory=True,
|
@@ -526,7 +495,7 @@ class AverageImagesInputSpec(ANTSCommandInputSpec):
|
526 | 495 | desc="Normalize: if true, the 2nd image is divided by its mean. "
|
527 | 496 | "This will select the largest image to average into.",
|
528 | 497 | )
|
529 |
| - images = InputMultiPath( |
| 498 | + images = InputMultiObject( |
530 | 499 | File(exists=True),
|
531 | 500 | argstr="%s",
|
532 | 501 | mandatory=True,
|
@@ -767,7 +736,7 @@ class ComposeMultiTransformInputSpec(ANTSCommandInputSpec):
|
767 | 736 | position=2,
|
768 | 737 | desc="Reference image (only necessary when output is warpfield)",
|
769 | 738 | )
|
770 |
| - transforms = InputMultiPath( |
| 739 | + transforms = InputMultiObject( |
771 | 740 | File(exists=True),
|
772 | 741 | argstr="%s",
|
773 | 742 | mandatory=True,
|
|
0 commit comments