Skip to content

Commit 29d955c

Browse files
committed
add all mrtrix interfaces for testing
1 parent 7a69cfb commit 29d955c

File tree

1 file changed

+239
-22
lines changed

1 file changed

+239
-22
lines changed

dmriprep/interfaces/mrtrix3.py

Lines changed: 239 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,265 @@
11
#!/usr/bin/env python
22

3-
from __future__ import (
4-
print_function,
5-
division,
6-
unicode_literals,
7-
absolute_import,
8-
)
3+
from __future__ import print_function, division, unicode_literals, absolute_import
94

105
from nipype.interfaces.base import traits, TraitedSpec, File
116
from nipype.interfaces.mrtrix3.base import MRTrix3BaseInputSpec, MRTrix3Base
127

138

14-
class MRResizeInputSpec(MRTrix3BaseInputSpec):
9+
class DWIDenoiseInputSpec(MRTrix3BaseInputSpec):
10+
in_file = File(
11+
exists=True, argstr="%s", position=-2, mandatory=True, desc="input DWI image"
12+
)
13+
mask = File(exists=True, argstr="-mask %s", position=1, desc="mask image")
14+
extent = traits.Tuple(
15+
(traits.Int, traits.Int, traits.Int),
16+
argstr="-extent %d,%d,%d",
17+
desc="set the window size of the denoising filter. (default = 5,5,5)",
18+
)
19+
noise = File(
20+
argstr="-noise %s",
21+
name_template="%s_noise",
22+
name_source="in_file",
23+
keep_extension=True,
24+
desc="the output noise map",
25+
)
26+
out_file = File(
27+
argstr="%s",
28+
position=-1,
29+
name_template="%s_denoised",
30+
name_source="in_file",
31+
keep_extension=True,
32+
desc="the output denoised DWI image",
33+
)
34+
35+
36+
class DWIDenoiseOutputSpec(TraitedSpec):
37+
noise = File(desc="the output noise map", exists=True)
38+
out_file = File(desc="the output denoised DWI image", exists=True)
39+
40+
41+
class DWIDenoise(MRTrix3Base):
42+
"""
43+
Denoise DWI data and estimate the noise level based on the optimal
44+
threshold for PCA.
45+
46+
DWI data denoising and noise map estimation by exploiting data redundancy
47+
in the PCA domain using the prior knowledge that the eigenspectrum of
48+
random covariance matrices is described by the universal Marchenko Pastur
49+
distribution.
50+
51+
Important note: image denoising must be performed as the first step of the
52+
image processing pipeline. The routine will fail if interpolation or
53+
smoothing has been applied to the data prior to denoising.
54+
55+
Note that this function does not correct for non-Gaussian noise biases.
56+
57+
For more information, see
58+
<https://mrtrix.readthedocs.io/en/latest/reference/commands/dwidenoise.html>
59+
60+
Example
61+
-------
62+
63+
>>> import nipype.interfaces.mrtrix3 as mrt
64+
>>> denoise = mrt.DWIDenoise()
65+
>>> denoise.inputs.in_file = 'dwi.mif'
66+
>>> denoise.inputs.mask = 'mask.mif'
67+
>>> denoise.inputs.noise = 'noise.mif'
68+
>>> denoise.cmdline # doctest: +ELLIPSIS
69+
'dwidenoise -mask mask.mif -noise noise.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+
78+
class MRDeGibbsInputSpec(MRTrix3BaseInputSpec):
1579
in_file = File(
16-
exists=True,
80+
exists=True, argstr="%s", position=-2, mandatory=True, desc="input DWI image"
81+
)
82+
axes = traits.ListInt(
83+
default_value=[0, 1],
84+
usedefault=True,
85+
sep=",",
86+
minlen=2,
87+
maxlen=2,
88+
argstr="-axes %s",
89+
desc="indicate the plane in which the data was acquired (axial = 0,1; "
90+
"coronal = 0,2; sagittal = 1,2",
91+
)
92+
nshifts = traits.Int(
93+
default_value=20,
94+
usedefault=True,
95+
argstr="-nshifts %d",
96+
desc="discretization of subpixel spacing (default = 20)",
97+
)
98+
minW = traits.Int(
99+
default_value=1,
100+
usedefault=True,
101+
argstr="-minW %d",
102+
desc="left border of window used for total variation (TV) computation "
103+
"(default = 1)",
104+
)
105+
maxW = traits.Int(
106+
default_value=3,
107+
usedefault=True,
108+
argstr="-maxW %d",
109+
desc="right border of window used for total variation (TV) computation "
110+
"(default = 3)",
111+
)
112+
out_file = File(
113+
name_template="%s_unr",
114+
name_source="in_file",
115+
keep_extension=True,
17116
argstr="%s",
18-
position=-2,
117+
position=-1,
118+
desc="the output unringed DWI image",
119+
)
120+
121+
122+
class MRDeGibbsOutputSpec(TraitedSpec):
123+
out_file = File(desc="the output unringed DWI image", exists=True)
124+
125+
126+
class MRDeGibbs(MRTrix3Base):
127+
"""
128+
Remove Gibbs ringing artifacts.
129+
130+
This application attempts to remove Gibbs ringing artefacts from MRI images
131+
using the method of local subvoxel-shifts proposed by Kellner et al.
132+
133+
This command is designed to run on data directly after it has been
134+
reconstructed by the scanner, before any interpolation of any kind has
135+
taken place. You should not run this command after any form of motion
136+
correction (e.g. not after dwipreproc). Similarly, if you intend running
137+
dwidenoise, you should run this command afterwards, since it has the
138+
potential to alter the noise structure, which would impact on dwidenoise's
139+
performance.
140+
141+
Note that this method is designed to work on images acquired with full
142+
k-space coverage. Running this method on partial Fourier ('half-scan') data
143+
may lead to suboptimal and/or biased results, as noted in the original
144+
reference below. There is currently no means of dealing with this; users
145+
should exercise caution when using this method on partial Fourier data, and
146+
inspect its output for any obvious artefacts.
147+
148+
For more information, see
149+
<https://mrtrix.readthedocs.io/en/latest/reference/commands/mrdegibbs.html>
150+
151+
Example
152+
-------
153+
154+
>>> import nipype.interfaces.mrtrix3 as mrt
155+
>>> unring = mrt.MRDeGibbs()
156+
>>> unring.inputs.in_file = 'dwi.mif'
157+
>>> unring.cmdline
158+
'mrdegibbs -axes 0,1 -maxW 3 -minW 1 -nshifts 20 dwi.mif dwi_unr.mif'
159+
>>> unring.run() # doctest: +SKIP
160+
"""
161+
162+
_cmd = "mrdegibbs"
163+
input_spec = MRDeGibbsInputSpec
164+
output_spec = MRDeGibbsOutputSpec
165+
166+
167+
class DWIBiasCorrectInputSpec(MRTrix3BaseInputSpec):
168+
in_file = File(
169+
exists=True, argstr="%s", position=-2, mandatory=True, desc="input DWI image"
170+
)
171+
in_mask = File(argstr="-mask %s", desc="input mask image for bias field estimation")
172+
use_ants = traits.Bool(
173+
argstr="-ants",
174+
mandatory=True,
175+
desc="use ANTS N4 to estimate the inhomogeneity field",
176+
xor=["use_fsl"],
177+
)
178+
use_fsl = traits.Bool(
179+
argstr="-fsl",
19180
mandatory=True,
20-
desc="input DWI image",
181+
desc="use FSL FAST to estimate the inhomogeneity field",
182+
xor=["use_ants"],
21183
)
22-
image_size = traits.List(
23-
traits.Int(),
24-
argstr="-size %s",
184+
bias = File(argstr="-bias %s", desc="bias field")
185+
out_file = File(
186+
name_template="%s_biascorr",
187+
name_source="in_file",
188+
keep_extension=True,
189+
argstr="%s",
190+
position=-1,
191+
desc="the output bias corrected DWI image",
192+
genfile=True,
193+
)
194+
195+
196+
class DWIBiasCorrectOutputSpec(TraitedSpec):
197+
bias = File(desc="the output bias field", exists=True)
198+
out_file = File(desc="the output bias corrected DWI image", exists=True)
199+
200+
201+
class DWIBiasCorrect(MRTrix3Base):
202+
"""
203+
Perform B1 field inhomogeneity correction for a DWI volume series.
204+
205+
For more information, see
206+
<https://mrtrix.readthedocs.io/en/latest/reference/scripts/dwibiascorrect.html>
207+
208+
Example
209+
-------
210+
211+
>>> import nipype.interfaces.mrtrix3 as mrt
212+
>>> bias_correct = mrt.DWIBiasCorrect()
213+
>>> bias_correct.inputs.in_file = 'dwi.mif'
214+
>>> bias_correct.inputs.use_ants = True
215+
>>> bias_correct.cmdline
216+
'dwibiascorrect -ants dwi.mif dwi_biascorr.mif'
217+
>>> bias_correct.run() # doctest: +SKIP
218+
"""
219+
220+
_cmd = "dwibiascorrect"
221+
input_spec = DWIBiasCorrectInputSpec
222+
output_spec = DWIBiasCorrectOutputSpec
223+
224+
225+
class MRResizeInputSpec(MRTrix3BaseInputSpec):
226+
in_file = File(
227+
exists=True, argstr="%s", position=-2, mandatory=True, desc="input DWI image"
228+
)
229+
image_size = traits.Tuple(
230+
(traits.Int, traits.Int, traits.Int),
231+
argstr="-size %d,%d,%d",
232+
mandatory=True,
25233
desc="define the new image size for the output image. This should be "
26234
"specified as a comma-separated list.",
235+
xor=["voxel_size", "scale_factor"],
27236
)
28-
voxel_size = traits.List(
29-
traits.Float(),
30-
argstr="-voxel %s",
237+
voxel_size = traits.Tuple(
238+
(traits.Float, traits.Float, traits.Float),
239+
argstr="-voxel %d,%d,%d",
240+
mandatory=True,
31241
desc="define the new voxel size for the output image. This can be "
32242
"specified either as a single value to be used for all "
33243
"dimensions, or as a comma-separated list of the size for each "
34244
"voxel dimension.",
245+
xor=["image_size", "scale_factor"],
35246
)
36-
scale_factor = traits.Float(
37-
argstr="-scale %s",
247+
scale_factor = traits.Tuple(
248+
(traits.Float, traits.Float, traits.Float),
249+
argstr="-scale %d,%d,%d",
250+
mandatory=True,
38251
desc="scale the image resolution by the supplied factor. This can be "
39252
"specified either as a single value to be used for all "
40253
"dimensions, or as a comma-separated list of scale factors for "
41254
"each dimension.",
255+
xor=["image_size", "voxel_size"],
42256
)
43257
interp = traits.Enum(
258+
"cubic",
44259
"nearest",
45260
"linear",
46-
"cubic",
47261
"sinc",
48-
default="cubic",
262+
usedefault=True,
49263
argstr="-interp %s",
50264
desc="set the interpolation method to use when resizing (choices: "
51265
"nearest, linear, cubic, sinc. Default: cubic).",
@@ -67,15 +281,18 @@ class MRResizeOutputSpec(TraitedSpec):
67281

68282
class MRResize(MRTrix3Base):
69283
"""
70-
Resize an image by defining the new image resolution, voxel size or a scale factor
284+
Resize an image by defining the new image resolution, voxel size or a
285+
scale factor. If the image is 4D, then only the first 3 dimensions can be
286+
resized. Also, if the image is down-sampled, the appropriate smoothing is
287+
automatically applied using Gaussian smoothing.
71288
For more information, see
72289
<https://mrtrix.readthedocs.io/en/latest/reference/commands/mrresize.html>
73290
Example
74291
-------
75292
>>> import nipype.interfaces.mrtrix3 as mrt
76293
>>> resize = mrt.MRResize()
77294
>>> resize.inputs.in_file = 'dwi.mif'
78-
>>> resize.inputs.scal_factor = 2
295+
>>> resize.inputs.scale_factor = 2
79296
>>> resize.cmdline # doctest: +ELLIPSIS
80297
'mrresize -scale 2 dwi.mif dwi_resized.mif'
81298
>>> resize.run() # doctest: +SKIP

0 commit comments

Comments
 (0)