@@ -121,28 +121,25 @@ class ApplyTransformInputSpec(SPMCommandInputSpec):
121
121
desc = 'file to apply transform to, (only updates header)' )
122
122
mat = File ( exists = True , mandatory = True ,
123
123
desc = 'file holding transform to apply' )
124
-
124
+ out_file = File (desc = "output file name for transformed data" ,
125
+ genfile = True )
125
126
126
127
class ApplyTransformOutputSpec (TraitedSpec ):
127
- out_file = File (exists = True , desc = 'File with updated header ' )
128
+ out_file = File (exists = True , desc = 'Transformed image file ' )
128
129
129
130
130
131
class ApplyTransform (SPMCommand ):
131
- """ Uses spm to apply transform stored in a .mat file to given file
132
+ """ Uses SPM to apply transform stored in a .mat file to given file
132
133
133
134
Examples
134
135
--------
135
136
136
137
>>> import nipype.interfaces.spm.utils as spmu
137
- >>> applymat = spmu.ApplyTransform(matlab_cmd='matlab-spm8' )
138
+ >>> applymat = spmu.ApplyTransform()
138
139
>>> applymat.inputs.in_file = 'functional.nii'
139
140
>>> applymat.inputs.mat = 'func_to_struct.mat'
140
141
>>> applymat.run() # doctest: +SKIP
141
142
142
- .. warning::
143
-
144
- CHANGES YOUR INPUT FILE (applies transform by updating the header)
145
- except when used with nipype caching or workflow.
146
143
"""
147
144
input_spec = ApplyTransformInputSpec
148
145
output_spec = ApplyTransformOutputSpec
@@ -151,19 +148,37 @@ def _make_matlab_command(self, _):
151
148
"""checks for SPM, generates script"""
152
149
script = """
153
150
infile = '%s';
151
+ outfile = '%s'
154
152
transform = load('%s');
155
- M = inv(transform.M);
156
- img_space = spm_get_space(infile);
157
- spm_get_space(infile, M * img_space);
153
+
154
+ V = spm_vol(infile);
155
+ X = spm_read_vols(V);
156
+ [p n e v] = spm_fileparts(V.fname);
157
+ V.mat = transform.M * V.mat;
158
+ V.fname = fullfile(outfile);
159
+ spm_write_vol(V,X);
160
+
158
161
""" % (self .inputs .in_file ,
162
+ self .inputs .out_file ,
159
163
self .inputs .mat )
164
+ #img_space = spm_get_space(infile);
165
+ #spm_get_space(infile, transform.M * img_space);
160
166
return script
161
167
162
168
def _list_outputs (self ):
163
- outputs = self ._outputs ().get ()
164
- outputs ['out_file' ] = os .path .abspath (self .inputs .in_file )
169
+ outputs = self .output_spec ().get ()
170
+ if not isdefined (self .inputs .out_file ):
171
+ _ , name , _ = split_filename (self .inputs .in_file )
172
+ outputs ['out_file' ] = os .path .abspath (name + '_trans.nii' )
173
+ else :
174
+ outputs ['out_file' ] = os .path .abspath (self .inputs .out_file )
165
175
return outputs
166
176
177
+ def _gen_filename (self , name ):
178
+ if name == 'out_file' :
179
+ return self ._list_outputs ()[name ]
180
+ return None
181
+
167
182
class ResliceInputSpec (SPMCommandInputSpec ):
168
183
in_file = File ( exists = True , mandatory = True ,
169
184
desc = 'file to apply transform to, (only updates header)' )
0 commit comments