Skip to content

Commit caf87f5

Browse files
authored
Merge pull request #2568 from mvdoc/nf/dwidenoise
ENH: add interface for MRTrix3's dwidenoise
2 parents 53e0662 + 3e33f0d commit caf87f5

File tree

3 files changed

+127
-1
lines changed

3 files changed

+127
-1
lines changed

nipype/interfaces/mrtrix3/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
from .utils import (Mesh2PVE, Generate5tt, BrainMask, TensorMetrics,
77
ComputeTDI, TCK2VTK, MRMath, MRConvert, DWIExtract)
8-
from .preprocess import ResponseSD, ACTPrepareFSL, ReplaceFSwithFIRST
8+
from .preprocess import (ResponseSD, ACTPrepareFSL, ReplaceFSwithFIRST,
9+
DWIDenoise)
910
from .tracking import Tractography
1011
from .reconst import FitTensor, EstimateFOD
1112
from .connectivity import LabelConfig, LabelConvert, BuildConnectome

nipype/interfaces/mrtrix3/preprocess.py

+64
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,70 @@
1111
from .base import MRTrix3BaseInputSpec, MRTrix3Base
1212

1313

14+
class DWIDenoiseInputSpec(MRTrix3BaseInputSpec):
15+
in_file = File(
16+
exists=True,
17+
argstr='%s',
18+
position=-2,
19+
mandatory=True,
20+
desc='input DWI image')
21+
mask = File(
22+
exists=True,
23+
argstr='-mask %s',
24+
position=1,
25+
desc='mask image')
26+
extent = traits.Tuple((traits.Int, traits.Int, traits.Int),
27+
argstr='-extent %d,%d,%d',
28+
desc='set the window size of the denoising filter. (default = 5,5,5)')
29+
noise = File(
30+
argstr='-noise %s',
31+
desc='noise map')
32+
out_file = File(name_template='%s_denoised',
33+
name_source='in_file',
34+
keep_extension=True,
35+
argstr="%s",
36+
position=-1,
37+
desc="the output denoised DWI image")
38+
39+
class DWIDenoiseOutputSpec(TraitedSpec):
40+
out_file = File(desc="the output denoised DWI image", exists=True)
41+
42+
class DWIDenoise(MRTrix3Base):
43+
"""
44+
Denoise DWI data and estimate the noise level based on the optimal
45+
threshold for PCA.
46+
47+
DWI data denoising and noise map estimation by exploiting data redundancy
48+
in the PCA domain using the prior knowledge that the eigenspectrum of
49+
random covariance matrices is described by the universal Marchenko Pastur
50+
distribution.
51+
52+
Important note: image denoising must be performed as the first step of the
53+
image processing pipeline. The routine will fail if interpolation or
54+
smoothing has been applied to the data prior to denoising.
55+
56+
Note that this function does not correct for non-Gaussian noise biases.
57+
58+
For more information, see
59+
<https://mrtrix.readthedocs.io/en/latest/reference/commands/dwidenoise.html>
60+
61+
Example
62+
-------
63+
64+
>>> import nipype.interfaces.mrtrix3 as mrt
65+
>>> denoise = mrt.DWIDenoise()
66+
>>> denoise.inputs.in_file = 'dwi.mif'
67+
>>> denoise.inputs.mask = 'mask.mif'
68+
>>> denoise.cmdline # doctest: +ELLIPSIS
69+
'dwidenoise -mask mask.mif dwi.mif dwi_denoised.mif'
70+
>>> denoise.run() # doctest: +SKIP
71+
"""
72+
73+
_cmd = 'dwidenoise'
74+
input_spec = DWIDenoiseInputSpec
75+
output_spec = DWIDenoiseOutputSpec
76+
77+
1478
class ResponseSDInputSpec(MRTrix3BaseInputSpec):
1579
algorithm = traits.Enum(
1680
'msmt_5tt',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..preprocess import DWIDenoise
4+
5+
6+
def test_DWIDenoise_inputs():
7+
input_map = dict(
8+
args=dict(argstr='%s', ),
9+
bval_scale=dict(argstr='-bvalue_scaling %s', ),
10+
environ=dict(
11+
nohash=True,
12+
usedefault=True,
13+
),
14+
extent=dict(argstr='-extent %d,%d,%d', ),
15+
grad_file=dict(argstr='-grad %s', ),
16+
grad_fsl=dict(argstr='-fslgrad %s %s', ),
17+
ignore_exception=dict(
18+
deprecated='1.0.0',
19+
nohash=True,
20+
usedefault=True,
21+
),
22+
in_bval=dict(),
23+
in_bvec=dict(argstr='-fslgrad %s %s', ),
24+
in_file=dict(
25+
argstr='%s',
26+
mandatory=True,
27+
position=-2,
28+
),
29+
mask=dict(
30+
argstr='-mask %s',
31+
position=1,
32+
),
33+
noise=dict(argstr='-noise %s', ),
34+
nthreads=dict(
35+
argstr='-nthreads %d',
36+
nohash=True,
37+
),
38+
out_file=dict(
39+
argstr='%s',
40+
keep_extension=True,
41+
name_source='in_file',
42+
name_template='%s_denoised',
43+
position=-1,
44+
),
45+
terminal_output=dict(
46+
deprecated='1.0.0',
47+
nohash=True,
48+
),
49+
)
50+
inputs = DWIDenoise.input_spec()
51+
52+
for key, metadata in list(input_map.items()):
53+
for metakey, value in list(metadata.items()):
54+
assert getattr(inputs.traits()[key], metakey) == value
55+
def test_DWIDenoise_outputs():
56+
output_map = dict(out_file=dict(), )
57+
outputs = DWIDenoise.output_spec()
58+
59+
for key, metadata in list(output_map.items()):
60+
for metakey, value in list(metadata.items()):
61+
assert getattr(outputs.traits()[key], metakey) == value

0 commit comments

Comments
 (0)