Skip to content

Commit e6bc85e

Browse files
committed
Merge remote-tracking branch 'bpinsard/spm/reslicetoref'
Conflicts: CHANGES
2 parents 6cdd49b + 47e5f5d commit e6bc85e

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
Next release
22
============
33

4+
* ENH: New interfaces: spm.ResliceToReference
5+
46
* FIX: Deals properly with 3d files in SPM Realign
57

8+
69
Release 0.8.0 (May 8, 2013)
710
===========================
811

nipype/interfaces/spm/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
from .model import (Level1Design, EstimateModel, EstimateContrast, Threshold,
1111
OneSampleTTestDesign, TwoSampleTTestDesign,
1212
PairedTTestDesign, MultipleRegressionDesign)
13-
from .utils import Analyze2nii, CalcCoregAffine, ApplyTransform, Reslice, ApplyInverseDeformation
13+
from .utils import Analyze2nii, CalcCoregAffine, ApplyTransform, Reslice, ApplyInverseDeformation,ResliceToReference
1414

nipype/interfaces/spm/utils.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,73 @@ def _list_outputs(self):
289289
_, fname = os.path.split(filename)
290290
outputs['out_files'].append(os.path.realpath('w%s' % fname))
291291
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

Comments
 (0)