Skip to content

Commit eacb55c

Browse files
committed
NF: add interface for MRTrix3's dwidenoise
1 parent 347c4b4 commit eacb55c

File tree

3 files changed

+140
-1
lines changed

3 files changed

+140
-1
lines changed

nipype/interfaces/mrtrix3/__init__.py

Lines changed: 2 additions & 1 deletion
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

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

0 commit comments

Comments
 (0)