diff --git a/nipype/interfaces/mrtrix3/__init__.py b/nipype/interfaces/mrtrix3/__init__.py index c9c131dde3..87b12e7442 100644 --- a/nipype/interfaces/mrtrix3/__init__.py +++ b/nipype/interfaces/mrtrix3/__init__.py @@ -4,7 +4,8 @@ # -*- coding: utf-8 -*- from .utils import (Mesh2PVE, Generate5tt, BrainMask, TensorMetrics, - ComputeTDI, TCK2VTK, MRMath, MRConvert, DWIExtract) + ComputeTDI, TCK2VTK, MRMath, MRConvert, MRResize, + DWIExtract) from .preprocess import (ResponseSD, ACTPrepareFSL, ReplaceFSwithFIRST, DWIDenoise, MRDeGibbs, DWIBiasCorrect) from .tracking import Tractography diff --git a/nipype/interfaces/mrtrix3/tests/test_auto_MRResize.py b/nipype/interfaces/mrtrix3/tests/test_auto_MRResize.py new file mode 100644 index 0000000000..a81528d44a --- /dev/null +++ b/nipype/interfaces/mrtrix3/tests/test_auto_MRResize.py @@ -0,0 +1,77 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..utils import MRResize + + +def test_MRResize_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + bval_scale=dict(argstr='-bvalue_scaling %s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + grad_file=dict( + argstr='-grad %s', + extensions=None, + xor=['grad_fsl'], + ), + grad_fsl=dict( + argstr='-fslgrad %s %s', + xor=['grad_file'], + ), + image_size=dict( + argstr='-size %d,%d,%d', + mandatory=True, + xor=['voxel_size', 'scale_factor'], + ), + in_bval=dict(extensions=None, ), + in_bvec=dict( + argstr='-fslgrad %s %s', + extensions=None, + ), + in_file=dict( + argstr='%s', + extensions=None, + mandatory=True, + position=-2, + ), + interpolation=dict( + argstr='-interp %s', + usedefault=True, + ), + nthreads=dict( + argstr='-nthreads %d', + nohash=True, + ), + out_file=dict( + argstr='%s', + extensions=None, + keep_extension=True, + name_source=['in_file'], + name_template='%s_resized', + position=-1, + ), + scale_factor=dict( + argstr='-scale %g,%g,%g', + mandatory=True, + xor=['image_size', 'voxel_size'], + ), + voxel_size=dict( + argstr='-voxel %g,%g,%g', + mandatory=True, + xor=['image_size', 'scale_factor'], + ), + ) + inputs = MRResize.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(inputs.traits()[key], metakey) == value +def test_MRResize_outputs(): + output_map = dict(out_file=dict(extensions=None, ), ) + outputs = MRResize.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/mrtrix3/utils.py b/nipype/interfaces/mrtrix3/utils.py index a667c716f4..52122189bf 100644 --- a/nipype/interfaces/mrtrix3/utils.py +++ b/nipype/interfaces/mrtrix3/utils.py @@ -677,3 +677,99 @@ def _list_outputs(self): outputs = self.output_spec().get() outputs['out_file'] = op.abspath(self.inputs.out_file) return outputs + + +class MRResizeInputSpec(MRTrix3BaseInputSpec): + in_file = File( + exists=True, + argstr='%s', + position=-2, + mandatory=True, + desc='input DWI image' + ) + image_size = traits.Tuple( + (traits.Int, traits.Int, traits.Int), + argstr='-size %d,%d,%d', + mandatory=True, + desc='Number of voxels in each dimension of output image', + xor=['voxel_size', 'scale_factor'], + ) + voxel_size = traits.Tuple( + (traits.Float, traits.Float, traits.Float), + argstr='-voxel %g,%g,%g', + mandatory=True, + desc='Desired voxel size in mm for the output image', + xor=['image_size', 'scale_factor'], + ) + scale_factor = traits.Tuple( + (traits.Float, traits.Float, traits.Float), + argstr='-scale %g,%g,%g', + mandatory=True, + desc='Scale factors to rescale the image by in each dimension', + xor=['image_size', 'voxel_size'], + ) + interpolation = traits.Enum( + 'cubic', + 'nearest', + 'linear', + 'sinc', + argstr='-interp %s', + usedefault=True, + desc='set the interpolation method to use when resizing (choices: ' + 'nearest, linear, cubic, sinc. Default: cubic).', + ) + out_file = File( + argstr='%s', + name_template='%s_resized', + name_source=['in_file'], + keep_extension=True, + position=-1, + desc='the output resized DWI image', + ) + + +class MRResizeOutputSpec(TraitedSpec): + out_file = File(desc='the output resized DWI image', exists=True) + + +class MRResize(MRTrix3Base): + """ + Resize an image by defining the new image resolution, voxel size or a + scale factor. If the image is 4D, then only the first 3 dimensions can be + resized. Also, if the image is down-sampled, the appropriate smoothing is + automatically applied using Gaussian smoothing. + For more information, see + + + Example + ------- + >>> import nipype.interfaces.mrtrix3 as mrt + + Defining the new image resolution: + >>> image_resize = mrt.MRResize() + >>> image_resize.inputs.in_file = 'dwi.mif' + >>> image_resize.inputs.image_size = (256, 256, 144) + >>> image_resize.cmdline # doctest: +ELLIPSIS + 'mrresize -size 256,256,144 -interp cubic dwi.mif dwi_resized.mif' + >>> image_resize.run() # doctest: +SKIP + + Defining the new image's voxel size: + >>> voxel_resize = mrt.MRResize() + >>> voxel_resize.inputs.in_file = 'dwi.mif' + >>> voxel_resize.inputs.voxel_size = (1, 1, 1) + >>> voxel_resize.cmdline # doctest: +ELLIPSIS + 'mrresize -interp cubic -voxel 1,1,1 dwi.mif dwi_resized.mif' + >>> voxel_resize.run() # doctest: +SKIP + + Defining the scale factor of each image dimension: + >>> scale_resize = mrt.MRResize() + >>> scale_resize.inputs.in_file = 'dwi.mif' + >>> scale_resize.inputs.scale_factor = (0.5,0.5,0.5) + >>> scale_resize.cmdline # doctest: +ELLIPSIS + 'mrresize -interp cubic -scale 0.5,0.5,0.5 dwi.mif dwi_resized.mif' + >>> scale_resize.run() # doctest: +SKIP + """ + + _cmd = 'mrresize' + input_spec = MRResizeInputSpec + output_spec = MRResizeOutputSpec