Skip to content

ENH: Add mrrtrix3.MRResize interface #3031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion nipype/interfaces/mrtrix3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 74 additions & 0 deletions nipype/interfaces/mrtrix3/tests/test_auto_MRResize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# 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,
),
interp=dict(argstr='-interp %s', ),
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 %d,%d,%d',
mandatory=True,
xor=['image_size', 'voxel_size'],
),
voxel_size=dict(
argstr='-voxel %d,%d,%d',
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
83 changes: 83 additions & 0 deletions nipype/interfaces/mrtrix3/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,3 +677,86 @@ 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='define the new image size for the output image. This should be '
'specified as a comma-separated list.',
xor=['voxel_size', 'scale_factor'],
)
voxel_size = traits.Tuple(
(traits.Float, traits.Float, traits.Float),
argstr='-voxel %d,%d,%d',
mandatory=True,
desc='define the new voxel size for the output image. This can be '
'specified either as a single value to be used for all '
'dimensions, or as a comma-separated list of the size for each '
'voxel dimension.',
xor=['image_size', 'scale_factor'],
)
scale_factor = traits.Tuple(
(traits.Float, traits.Float, traits.Float),
argstr='-scale %d,%d,%d',
mandatory=True,
desc='scale the image resolution by the supplied factor. This can be '
'specified either as a single value to be used for all '
'dimensions, or as a comma-separated list of scale factors for '
'each dimension.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, something like

desc='Scale factors to rescale the image by in each dimension'

xor=['image_size', 'voxel_size'],
)
interp = traits.Enum(
'cubic',
'nearest',
'linear',
'sinc',
argstr='-interp %s',
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
<https://mrtrix.readthedocs.io/en/latest/reference/commands/mrresize.html>
Example
-------
>>> import nipype.interfaces.mrtrix3 as mrt
>>> resize = mrt.MRResize()
>>> resize.inputs.in_file = 'dwi.mif'
>>> resize.inputs.voxel_size = (1, 1, 1)
>>> resize.cmdline # doctest: +ELLIPSIS
'mrresize -voxel 1,1,1 dwi.mif dwi_resized.mif'
>>> resize.run() # doctest: +SKIP
"""

_cmd = 'mrresize'
input_spec = MRResizeInputSpec
output_spec = MRResizeOutputSpec