16
16
from ...utils .filemanip import split_filename
17
17
from nipype .interfaces .base import InputMultiPath
18
18
19
+
19
20
class AverageAffineTransformInputSpec (ANTSCommandInputSpec ):
20
21
dimension = traits .Enum (3 , 2 , argstr = '%d' , usedefault = False , mandatory = True , position = 0 , desc = 'image dimension (2 or 3)' )
21
22
output_affine_transform = File (argstr = '%s' , mandatory = True , position = 1 , desc = 'Outputfname.txt: the name of the resulting transform.' )
22
- transforms = InputMultiPath (File (exists = True ), argstr = '%s' , mandatory = True , position = 3 , desc = ('transforms to average' ) )
23
+ transforms = InputMultiPath (File (exists = True ), argstr = '%s' , mandatory = True ,
24
+ position = 3 , desc = ('transforms to average' ))
25
+
23
26
24
27
class AverageAffineTransformOutputSpec (TraitedSpec ):
25
28
affine_transform = File (exists = True , desc = 'average transform file' )
26
29
30
+
27
31
class AverageAffineTransform (ANTSCommand ):
28
32
"""
29
33
Examples
@@ -45,20 +49,24 @@ def _format_arg(self, opt, spec, val):
45
49
46
50
def _list_outputs (self ):
47
51
outputs = self ._outputs ().get ()
48
- outputs ['affine_transform' ] = os .path .abspath (self .inputs .output_affine_transform )
52
+ outputs ['affine_transform' ] = os .path .abspath (
53
+ self .inputs .output_affine_transform )
49
54
return outputs
50
55
51
56
52
57
class AverageImagesInputSpec (ANTSCommandInputSpec ):
53
- dimension = traits .Enum (3 , 2 , argstr = '%d' , mandatory = True , position = 0 , desc = 'image dimension (2 or 3)' )
58
+ dimension = traits .Enum (3 , 2 , argstr = '%d' , mandatory = True ,
59
+ position = 0 , desc = 'image dimension (2 or 3)' )
54
60
output_average_image = File ("average.nii" , argstr = '%s' , position = 1 , desc = 'the name of the resulting image.' , usedefault = True , hash_files = False )
55
61
normalize = traits .Bool (argstr = "%d" , mandatory = True , position = 2 , desc = 'Normalize: if true, the 2nd image' +
56
62
'is divided by its mean. This will select the largest image to average into.' )
57
- images = InputMultiPath (File (exists = True ), argstr = '%s' , mandatory = True , position = 3 , desc = ('image to apply transformation to (generally a coregistered functional)' ) )
63
+ images = InputMultiPath (File (exists = True ), argstr = '%s' , mandatory = True , position = 3 , desc = ('image to apply transformation to (generally a coregistered functional)' ))
64
+
58
65
59
66
class AverageImagesOutputSpec (TraitedSpec ):
60
67
output_average_image = File (exists = True , desc = 'average image file' )
61
68
69
+
62
70
class AverageImages (ANTSCommand ):
63
71
"""
64
72
Examples
@@ -81,18 +89,23 @@ def _format_arg(self, opt, spec, val):
81
89
82
90
def _list_outputs (self ):
83
91
outputs = self ._outputs ().get ()
84
- outputs ['output_average_image' ] = os .path .realpath (self .inputs .output_average_image )
92
+ outputs ['output_average_image' ] = os .path .realpath (
93
+ self .inputs .output_average_image )
85
94
return outputs
86
95
96
+
87
97
class MultiplyImagesInputSpec (ANTSCommandInputSpec ):
88
98
dimension = traits .Enum (3 , 2 , argstr = '%d' , usedefault = False , mandatory = True , position = 0 , desc = 'image dimension (2 or 3)' )
89
- first_input = File (argstr = '%s' , exists = True , mandatory = True , position = 1 , desc = 'image 1' )
99
+ first_input = File (
100
+ argstr = '%s' , exists = True , mandatory = True , position = 1 , desc = 'image 1' )
90
101
second_input = traits .Either (File (exists = True ), traits .Float , argstr = '%s' , mandatory = True , position = 2 , desc = 'image 2 or multiplication weight' )
91
102
output_product_image = File (argstr = '%s' , mandatory = True , position = 3 , desc = 'Outputfname.nii.gz: the name of the resulting image.' )
92
103
104
+
93
105
class MultiplyImagesOutputSpec (TraitedSpec ):
94
106
output_product_image = File (exists = True , desc = 'average image file' )
95
107
108
+
96
109
class MultiplyImages (ANTSCommand ):
97
110
"""
98
111
Examples
@@ -115,5 +128,61 @@ def _format_arg(self, opt, spec, val):
115
128
116
129
def _list_outputs (self ):
117
130
outputs = self ._outputs ().get ()
118
- outputs ['output_product_image' ] = os .path .abspath (self .inputs .output_product_image )
131
+ outputs ['output_product_image' ] = os .path .abspath (
132
+ self .inputs .output_product_image )
133
+ return outputs
134
+
135
+
136
+ class JacobianDeterminantInputSpec (ANTSCommandInputSpec ):
137
+ dimension = traits .Enum (3 , 2 , argstr = '%d' , usedefault = False , mandatory = True , position = 0 , desc = 'image dimension (2 or 3)' )
138
+ warp_file = File (argstr = '%s' , exists = True , mandatory = True ,
139
+ position = 1 , desc = 'input warp file' )
140
+ output_prefix = File (argstr = '%s' , genfile = True , hash_files = False , position = 2 , desc = 'prefix of the output image filename: PREFIX(log)jacobian.nii.gz' )
141
+ use_log = traits .Enum (0 , 1 , argstr = '%d' , mandatory = False , position = 3 ,
142
+ desc = 'log transform the jacobian determinant' )
143
+ template_mask = File (argstr = '%s' , exists = True , mandatory = False , position = 4 ,
144
+ desc = 'template mask to adjust for head size' )
145
+ norm_by_total = traits .Enum (0 , 1 , argstr = '%d' , mandatory = False , position = 5 , desc = 'normalize jacobian by total in mask to adjust for head size' )
146
+ projection_vector = traits .List (traits .Float (), argstr = '%s' , sep = 'x' , mandatory = False , position = 6 , desc = 'vector to project warp against' )
147
+
148
+
149
+ class JacobianDeterminantOutputSpec (TraitedSpec ):
150
+ jacobian_image = File (exists = True , desc = '(log transformed) jacobian image' )
151
+
152
+
153
+ class JacobianDeterminant (ANTSCommand ):
154
+ """
155
+ Examples
156
+ --------
157
+ >>> from nipype.interfaces.ants import JacobianDeterminant
158
+ >>> jacobian = JacobianDeterminant()
159
+ >>> jacobian.inputs.dimension = 3
160
+ >>> jacobian.inputs.warp_file = 'ants_Warp.nii.gz'
161
+ >>> jacobian.inputs.output_prefix = 'Sub001_'
162
+ >>> jacobian.inputs.use_log = 1
163
+ >>> jacobian.cmdline
164
+ 'ANTSJacobian 3 ants_Warp.nii.gz Sub001_ 1'
165
+ """
166
+
167
+ _cmd = 'ANTSJacobian'
168
+ input_spec = JacobianDeterminantInputSpec
169
+ output_spec = JacobianDeterminantOutputSpec
170
+
171
+ def _gen_filename (self , name ):
172
+ if name == 'output_prefix' :
173
+ output = self .inputs .output_prefix
174
+ if not isdefined (output ):
175
+ _ , name , ext = split_filename (self .inputs .warp_file )
176
+ output = name + '_'
177
+ return output
178
+ return None
179
+
180
+ def _list_outputs (self ):
181
+ outputs = self ._outputs ().get ()
182
+ if self .inputs .use_log == 1 :
183
+ outputs ['jacobian_image' ] = os .path .abspath (
184
+ self ._gen_filename ('output_prefix' ) + 'logjacobian.nii.gz' )
185
+ else :
186
+ outputs ['jacobian_image' ] = os .path .abspath (
187
+ self ._gen_filename ('output_prefix' ) + 'jacobian.nii.gz' )
119
188
return outputs
0 commit comments