@@ -289,3 +289,73 @@ def _list_outputs(self):
289
289
_ , fname = os .path .split (filename )
290
290
outputs ['out_files' ].append (os .path .realpath ('w%s' % fname ))
291
291
return outputs
292
+
293
+
294
+ class ResliceToReferenceInput (SPMCommandInputSpec ):
295
+ in_files = InputMultiPath (
296
+ File (exists = True ), mandatory = True , field = 'fnames' ,
297
+ desc = 'Files on which deformation is applied' )
298
+ target = File (
299
+ exists = True ,
300
+ field = 'comp{1}.id.space' ,
301
+ desc = 'File defining target space' )
302
+ interpolation = traits .Range (
303
+ low = 0 , hign = 7 , field = 'interp' ,
304
+ desc = 'degree of b-spline used for interpolation' )
305
+
306
+ bounding_box = traits .List (
307
+ traits .Float (),
308
+ field = 'comp{2}.idbbvox.bb' ,
309
+ minlen = 6 , maxlen = 6 ,
310
+ desc = '6-element list (opt)' )
311
+ voxel_sizes = traits .List (
312
+ traits .Float (),
313
+ field = 'comp{2}.idbbvox.vox' ,
314
+ minlen = 3 , maxlen = 3 ,
315
+ desc = '3-element list (opt)' )
316
+
317
+
318
+ class ResliceToReferenceOutput (TraitedSpec ):
319
+ out_files = OutputMultiPath (File (exists = True ),
320
+ desc = 'Transformed files' )
321
+
322
+
323
+ class ResliceToReference (SPMCommand ):
324
+ """ Uses spm to reslice a volume to a target image space or to a provided voxel size and bounding box
325
+
326
+ Examples
327
+ --------
328
+
329
+ >>> import nipype.interfaces.spm.utils as spmu
330
+ >>> r2ref = spmu.ResliceToReference()
331
+ >>> r2ref.inputs.in_files = 'functional.nii'
332
+ >>> r2ref.inputs.target = 'structural.nii'
333
+ >>> r2ref.run() # doctest: +SKIP
334
+ """
335
+
336
+ input_spec = ResliceToReferenceInput
337
+ output_spec = ResliceToReferenceOutput
338
+
339
+ _jobtype = 'util'
340
+ _jobname = 'defs'
341
+
342
+ def _format_arg (self , opt , spec , val ):
343
+ """Convert input to appropriate format for spm
344
+ """
345
+ if opt == 'in_files' :
346
+ return scans_for_fnames (filename_to_list (val ))
347
+ if opt == 'target' :
348
+ return scans_for_fname (filename_to_list (val ))
349
+ if opt == 'deformation' :
350
+ return np .array ([list_to_filename (val )], dtype = object )
351
+ if opt == 'deformation_field' :
352
+ return np .array ([list_to_filename (val )], dtype = object )
353
+ return val
354
+
355
+ def _list_outputs (self ):
356
+ outputs = self ._outputs ().get ()
357
+ outputs ['out_files' ] = []
358
+ for filename in self .inputs .in_files :
359
+ _ , fname = os .path .split (filename )
360
+ outputs ['out_files' ].append (os .path .realpath ('w%s' % fname ))
361
+ return outputs
0 commit comments