-
Notifications
You must be signed in to change notification settings - Fork 533
[ENH]: Add mrdegibbs and dwibiascorrect from mrtrix3 #2904
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
Changes from 9 commits
6a49acd
80dc7b2
c32258c
83bc6a4
ef7c805
51b6f15
6512e7a
059f3ee
572d2e6
dde5c4f
348d349
1334636
7015004
c08051d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,18 +26,23 @@ class DWIDenoiseInputSpec(MRTrix3BaseInputSpec): | |
extent = traits.Tuple((traits.Int, traits.Int, traits.Int), | ||
argstr='-extent %d,%d,%d', | ||
desc='set the window size of the denoising filter. (default = 5,5,5)') | ||
noise = File( | ||
out_noisemap = File(name_template='%s_noisemap', | ||
name_source='in_file', | ||
keep_extension=True, | ||
argstr='-noise %s', | ||
desc='noise map') | ||
desc='the output noise map', | ||
genfile=True) | ||
out_file = File(name_template='%s_denoised', | ||
name_source='in_file', | ||
keep_extension=True, | ||
argstr="%s", | ||
argstr='%s', | ||
position=-1, | ||
desc="the output denoised DWI image") | ||
desc='the output denoised DWI image', | ||
genfile=True) | ||
|
||
class DWIDenoiseOutputSpec(TraitedSpec): | ||
out_file = File(desc="the output denoised DWI image", exists=True) | ||
out_noisemap = File(desc='the output noise map', exists=True) | ||
out_file = File(desc='the output denoised DWI image', exists=True) | ||
|
||
class DWIDenoise(MRTrix3Base): | ||
""" | ||
|
@@ -66,7 +71,7 @@ class DWIDenoise(MRTrix3Base): | |
>>> denoise.inputs.in_file = 'dwi.mif' | ||
>>> denoise.inputs.mask = 'mask.mif' | ||
>>> denoise.cmdline # doctest: +ELLIPSIS | ||
'dwidenoise -mask mask.mif dwi.mif dwi_denoised.mif' | ||
'dwidenoise -mask mask.mif -noise dwi_noisemap.mif dwi.mif dwi_denoised.mif' | ||
>>> denoise.run() # doctest: +SKIP | ||
""" | ||
|
||
|
@@ -75,6 +80,163 @@ class DWIDenoise(MRTrix3Base): | |
output_spec = DWIDenoiseOutputSpec | ||
|
||
|
||
class MRDeGibbsInputSpec(MRTrix3BaseInputSpec): | ||
in_file = File( | ||
exists=True, | ||
argstr='%s', | ||
position=-2, | ||
mandatory=True, | ||
desc='input DWI image') | ||
axes = traits.ListInt( | ||
default_value=[0,1], | ||
usedefault=True, | ||
sep=',', | ||
minlen=2, | ||
maxlen=2, | ||
argstr='-axes %s', | ||
desc='indicate the plane in which the data was acquired (axial = 0,1; ' | ||
'coronal = 0,2; sagittal = 1,2') | ||
nshifts = traits.Int( | ||
default_value=20, | ||
usedefault=True, | ||
argstr='-nshifts %d', | ||
desc='discretization of subpixel spacing (default = 20)') | ||
minW = traits.Int( | ||
default_value=1, | ||
usedefault=True, | ||
argstr='-minW %d', | ||
desc='left border of window used for total variation (TV) computation ' | ||
'(default = 1)') | ||
maxW = traits.Int( | ||
default_value=3, | ||
usedefault=True, | ||
argstr='-maxW %d', | ||
desc='right border of window used for total variation (TV) computation ' | ||
'(default = 3)') | ||
out_file = File(name_template='%s_unr', | ||
name_source='in_file', | ||
keep_extension=True, | ||
argstr='%s', | ||
position=-1, | ||
desc='the output unringed DWI image', | ||
genfile=True) | ||
|
||
class MRDeGibbsOutputSpec(TraitedSpec): | ||
out_file = File(desc='the output unringed DWI image', exists=True) | ||
|
||
class MRDeGibbs(MRTrix3Base): | ||
""" | ||
Remove Gibbs ringing artifacts. | ||
|
||
This application attempts to remove Gibbs ringing artefacts from MRI images | ||
using the method of local subvoxel-shifts proposed by Kellner et al. | ||
|
||
This command is designed to run on data directly after it has been | ||
reconstructed by the scanner, before any interpolation of any kind has | ||
taken place. You should not run this command after any form of motion | ||
correction (e.g. not after dwipreproc). Similarly, if you intend running | ||
dwidenoise, you should run this command afterwards, since it has the | ||
potential to alter the noise structure, which would impact on dwidenoise’s | ||
performance. | ||
|
||
Note that this method is designed to work on images acquired with full | ||
k-space coverage. Running this method on partial Fourier (‘half-scan’) data | ||
may lead to suboptimal and/or biased results, as noted in the original | ||
reference below. There is currently no means of dealing with this; users | ||
should exercise caution when using this method on partial Fourier data, and | ||
inspect its output for any obvious artefacts. | ||
|
||
For more information, see | ||
<https://mrtrix.readthedocs.io/en/latest/reference/commands/mrdegibbs.html> | ||
|
||
Example | ||
------- | ||
|
||
>>> import nipype.interfaces.mrtrix3 as mrt | ||
>>> unring = mrt.MRDeGibbs() | ||
>>> unring.inputs.in_file = 'dwi.mif' | ||
>>> unring.cmdline # doctest: +ELLIPSIS | ||
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. i don't think you need the |
||
'mrdegibbs -axes 0,1 -maxW 3 -minW 1 -nshifts 20 dwi.mif dwi_unr.mif' | ||
>>> unring.run() # doctest: +SKIP | ||
""" | ||
|
||
_cmd = 'mrdegibbs' | ||
input_spec = MRDeGibbsInputSpec | ||
output_spec = MRDeGibbsOutputSpec | ||
|
||
|
||
class DWIBiasCorrectInputSpec(MRTrix3BaseInputSpec): | ||
in_file = File( | ||
exists=True, | ||
argstr='%s', | ||
position=-2, | ||
mandatory=True, | ||
desc='input DWI image') | ||
in_mask = File( | ||
argstr='-mask %s', | ||
desc='input mask image for bias field estimation') | ||
_xor_methods = ('use_ants', 'use_fsl') | ||
use_ants = traits.Bool( | ||
default_value=True, | ||
usedefault=True, | ||
argstr='-ants', | ||
desc='use ANTS N4 to estimate the inhomogeneity field', | ||
xor=_xor_methods) | ||
use_fsl = traits.Bool( | ||
argstr='-fsl', | ||
desc='use FSL FAST to estimate the inhomogeneity field', | ||
xor=_xor_methods, | ||
min_ver='5.0.10') | ||
_xor_grads = ('mrtrix_grad', 'fsl_grad') | ||
mrtrix_grad = File( | ||
argstr='-grad %s', | ||
desc='diffusion gradient table in MRtrix format', | ||
xor=_xor_grads) | ||
fsl_grad = File( | ||
argstr='-fslgrad %s %s', | ||
desc='diffusion gradient table in FSL bvecs/bvals format', | ||
xor=_xor_grads) | ||
out_bias = File(name_template='%s_biasfield', | ||
name_source='in_file', | ||
keep_extension=True, | ||
argstr='-bias %s', | ||
desc='bias field', | ||
genfile=True) | ||
out_file = File(name_template='%s_biascorr', | ||
name_source='in_file', | ||
keep_extension=True, | ||
argstr='%s', | ||
position=-1, | ||
desc='the output bias corrected DWI image', | ||
genfile=True) | ||
|
||
class DWIBiasCorrectOutputSpec(TraitedSpec): | ||
out_bias = File(desc='the output estimated bias field') | ||
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. is this always output? |
||
out_file = File(desc='the output bias corrected DWI image', exists=True) | ||
|
||
class DWIBiasCorrect(MRTrix3Base): | ||
""" | ||
Perform B1 field inhomogeneity correction for a DWI volume series. | ||
|
||
For more information, see | ||
<https://mrtrix.readthedocs.io/en/latest/reference/scripts/dwibiascorrect.html> | ||
|
||
Example | ||
------- | ||
|
||
>>> import nipype.interfaces.mrtrix3 as mrt | ||
>>> bias_correct = mrt.DWIBiasCorrect() | ||
>>> bias_correct.inputs.in_file = 'dwi.mif' | ||
>>> bias_correct.cmdline # doctest: +ELLIPSIS | ||
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. ellipsis not needed |
||
'dwibiascorrect -ants -bias dwi_biasfield.mif dwi.mif dwi_biascorr.mif' | ||
>>> bias_correct.run() # doctest: +SKIP | ||
""" | ||
|
||
_cmd = 'dwibiascorrect' | ||
input_spec = DWIBiasCorrectInputSpec | ||
output_spec = DWIBiasCorrectOutputSpec | ||
|
||
|
||
class ResponseSDInputSpec(MRTrix3BaseInputSpec): | ||
algorithm = traits.Enum( | ||
'msmt_5tt', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT | ||
from __future__ import unicode_literals | ||
from ..preprocess import DWIBiasCorrect | ||
|
||
|
||
def test_DWIBiasCorrect_inputs(): | ||
input_map = dict( | ||
args=dict(argstr='%s', ), | ||
bval_scale=dict(argstr='-bvalue_scaling %s', ), | ||
environ=dict( | ||
nohash=True, | ||
usedefault=True, | ||
), | ||
fsl_grad=dict( | ||
argstr='-fslgrad %s %s', | ||
xor=('mrtrix_grad', 'fsl_grad'), | ||
), | ||
grad_file=dict(argstr='-grad %s', ), | ||
grad_fsl=dict(argstr='-fslgrad %s %s', ), | ||
in_bval=dict(), | ||
in_bvec=dict(argstr='-fslgrad %s %s', ), | ||
in_file=dict( | ||
argstr='%s', | ||
mandatory=True, | ||
position=-2, | ||
), | ||
in_mask=dict(argstr='-mask %s', ), | ||
mrtrix_grad=dict( | ||
argstr='-grad %s', | ||
xor=('mrtrix_grad', 'fsl_grad'), | ||
), | ||
nthreads=dict( | ||
argstr='-nthreads %d', | ||
nohash=True, | ||
), | ||
out_bias=dict( | ||
argstr='-bias %s', | ||
genfile=True, | ||
keep_extension=True, | ||
name_source='in_file', | ||
name_template='%s_biasfield', | ||
), | ||
out_file=dict( | ||
argstr='%s', | ||
genfile=True, | ||
keep_extension=True, | ||
name_source='in_file', | ||
name_template='%s_biascorr', | ||
position=-1, | ||
), | ||
use_ants=dict( | ||
argstr='-ants', | ||
usedefault=True, | ||
xor=('use_ants', 'use_fsl'), | ||
), | ||
use_fsl=dict( | ||
argstr='-fsl', | ||
min_ver='5.0.10', | ||
xor=('use_ants', 'use_fsl'), | ||
), | ||
) | ||
inputs = DWIBiasCorrect.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_DWIBiasCorrect_outputs(): | ||
output_map = dict( | ||
out_bias=dict(), | ||
out_file=dict(), | ||
) | ||
outputs = DWIBiasCorrect.output_spec() | ||
|
||
for key, metadata in list(output_map.items()): | ||
for metakey, value in list(metadata.items()): | ||
assert getattr(outputs.traits()[key], metakey) == value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this always output?