3
3
# @Author: oesteban
4
4
# @Date: 2014-09-01 10:33:35
5
5
# @Last Modified by: oesteban
6
- # @Last Modified time: 2014-09-02 01:12:14
6
+ # @Last Modified time: 2014-09-02 16:00:36
7
7
from nipype .interfaces .base import (traits , TraitedSpec , BaseInterface ,
8
8
File , isdefined )
9
9
from nipype .utils .filemanip import split_filename
@@ -93,6 +93,8 @@ class DenoiseInputSpec(TraitedSpec):
93
93
noise_model = traits .Enum ('rician' , 'gaussian' , mandatory = True ,
94
94
usedefault = True ,
95
95
desc = ('noise distribution model' ))
96
+ noise_mask = File (desc = ('mask in which the standard deviation of noise '
97
+ 'will be computed' ), exists = True )
96
98
97
99
98
100
class DenoiseOutputSpec (TraitedSpec ):
@@ -129,7 +131,12 @@ def _run_interface(self, runtime):
129
131
if isdefined (self .inputs .in_mask ):
130
132
mask = nb .load (self .inputs .in_mask ).get_data ()
131
133
134
+ noise_mask = None
135
+ if isdefined (self .inputs .in_mask ):
136
+ noise_mask = nb .load (self .inputs .noise_mask ).get_data ()
137
+
132
138
nlmeans_proxy (self .inputs .in_file , in_mask = mask ,
139
+ noise_mask = noise_mask ,
133
140
rician = (self .inputs .noise_model == 'rician' ),
134
141
out_file = out_file )
135
142
iflogger .info ('Denoised image saved as {i}' .format (i = out_file ))
@@ -184,7 +191,8 @@ def resample_proxy(in_file, order=3, new_zooms=None, out_file=None):
184
191
return out_file , new_zooms
185
192
186
193
187
- def nlmeans_proxy (in_file , in_mask = None , rician = True , out_file = None ):
194
+ def nlmeans_proxy (in_file , in_mask = None , rician = True ,
195
+ noise_mask = None , out_file = None ):
188
196
"""
189
197
Uses non-local means to denoise 4D datasets
190
198
"""
@@ -206,7 +214,11 @@ def nlmeans_proxy(in_file, in_mask=None, rician=True, out_file=None):
206
214
else :
207
215
mask = in_mask > 0
208
216
209
- sigma = np .std (data [~ mask ])
217
+ nmask = mask
218
+ if noise_mask is not None :
219
+ nmask = noise_mask > 0
220
+
221
+ sigma = np .std (data [~ nmask ])
210
222
den = nlmeans (data , sigma = sigma , mask = mask )
211
223
212
224
nb .Nifti1Image (den .astype (hdr .get_data_dtype ()), aff ,
0 commit comments