-
Notifications
You must be signed in to change notification settings - Fork 535
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
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8e95244
add mrresize
josephmje d38f71c
Apply suggestions from code review
josephmje 270de32
Apply suggestions from code review
josephmje 1327e5b
Apply suggestions from code review
josephmje 0f0924a
include multiple examples
josephmje 593aea8
update doctests
josephmje 57e83fd
update test
josephmje File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.', | ||
josephmje marked this conversation as resolved.
Show resolved
Hide resolved
|
||
xor=['voxel_size', 'scale_factor'], | ||
) | ||
voxel_size = traits.Tuple( | ||
(traits.Float, traits.Float, traits.Float), | ||
argstr='-voxel %d,%d,%d', | ||
josephmje marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.', | ||
josephmje marked this conversation as resolved.
Show resolved
Hide resolved
|
||
xor=['image_size', 'scale_factor'], | ||
) | ||
scale_factor = traits.Tuple( | ||
(traits.Float, traits.Float, traits.Float), | ||
argstr='-scale %d,%d,%d', | ||
josephmje marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
josephmje marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'cubic', | ||
'nearest', | ||
'linear', | ||
'sinc', | ||
argstr='-interp %s', | ||
josephmje marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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> | ||
josephmje marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
""" | ||
josephmje marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
_cmd = 'mrresize' | ||
input_spec = MRResizeInputSpec | ||
output_spec = MRResizeOutputSpec |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.