Skip to content

Commit 70993fc

Browse files
committed
enable all options in Denoise
1 parent 4fca4ae commit 70993fc

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

nipype/interfaces/dipy/preprocess.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# @Author: oesteban
44
# @Date: 2014-09-01 10:33:35
55
# @Last Modified by: oesteban
6-
# @Last Modified time: 2014-09-02 16:00:36
6+
# @Last Modified time: 2014-09-03 15:07:46
77
from nipype.interfaces.base import (traits, TraitedSpec, BaseInterface,
88
File, isdefined)
99
from nipype.utils.filemanip import split_filename
@@ -95,6 +95,8 @@ class DenoiseInputSpec(TraitedSpec):
9595
desc=('noise distribution model'))
9696
noise_mask = File(desc=('mask in which the standard deviation of noise '
9797
'will be computed'), exists=True)
98+
patch_radius = traits.Int(1, desc='patch radius')
99+
block_radius = traits.Int(5, desc='block_radius')
98100

99101

100102
class DenoiseOutputSpec(TraitedSpec):
@@ -127,19 +129,28 @@ class Denoise(BaseInterface):
127129
def _run_interface(self, runtime):
128130
out_file = op.abspath(self._gen_outfilename())
129131

130-
mask = None
132+
settings = dict(mask=None,
133+
rician=(self.inputs.noise_model == 'rician'))
134+
131135
if isdefined(self.inputs.in_mask):
132-
mask = nb.load(self.inputs.in_mask).get_data()
136+
settings['mask'] = nb.load(self.inputs.in_mask).get_data()
137+
138+
if isdefined(self.inputs.patch_radius):
139+
settings['patch_radius'] = self.inputs.patch_radius
140+
141+
if isdefined(self.inputs.block_radius):
142+
settings['block_radius'] = self.inputs.block_radius
133143

134144
noise_mask = None
135145
if isdefined(self.inputs.in_mask):
136146
noise_mask = nb.load(self.inputs.noise_mask).get_data()
137147

138-
nlmeans_proxy(self.inputs.in_file, in_mask=mask,
139-
noise_mask=noise_mask,
140-
rician=(self.inputs.noise_model == 'rician'),
141-
out_file=out_file)
142-
iflogger.info('Denoised image saved as {i}'.format(i=out_file))
148+
_, s = nlmeans_proxy(self.inputs.in_file,
149+
settings,
150+
noise_mask=noise_mask,
151+
out_file=out_file)
152+
iflogger.info(('Denoised image saved as {i}, estimated '
153+
'sigma={s}').format(i=out_file, s=s))
143154
return runtime
144155

145156
def _list_outputs(self):
@@ -191,7 +202,7 @@ def resample_proxy(in_file, order=3, new_zooms=None, out_file=None):
191202
return out_file, new_zooms
192203

193204

194-
def nlmeans_proxy(in_file, in_mask=None, rician=True,
205+
def nlmeans_proxy(in_file, settings,
195206
noise_mask=None, out_file=None):
196207
"""
197208
Uses non-local means to denoise 4D datasets
@@ -209,18 +220,13 @@ def nlmeans_proxy(in_file, in_mask=None, rician=True,
209220
data = img.get_data()
210221
aff = img.get_affine()
211222

212-
if in_mask is None:
213-
mask = data[..., 0] > 80
214-
else:
215-
mask = in_mask > 0
216-
217-
nmask = mask
223+
nmask = data[..., 0] > 80
218224
if noise_mask is not None:
219225
nmask = noise_mask > 0
220226

221-
sigma = np.std(data[~nmask])
222-
den = nlmeans(data, sigma=sigma, mask=mask)
227+
sigma = np.std(data[nmask == 1])
228+
den = nlmeans(data, sigma, **settings)
223229

224230
nb.Nifti1Image(den.astype(hdr.get_data_dtype()), aff,
225231
hdr).to_filename(out_file)
226-
return out_file
232+
return out_file, sigma

nipype/interfaces/dipy/tests/test_auto_Denoise.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
from nipype.interfaces.dipy.preprocess import Denoise
44

55
def test_Denoise_inputs():
6-
input_map = dict(in_file=dict(mandatory=True,
6+
input_map = dict(block_radius=dict(),
7+
in_file=dict(mandatory=True,
78
),
89
in_mask=dict(),
910
noise_mask=dict(),
1011
noise_model=dict(mandatory=True,
1112
usedefault=True,
1213
),
14+
patch_radius=dict(),
1315
)
1416
inputs = Denoise.input_spec()
1517

0 commit comments

Comments
 (0)