forked from VincentToups/matlab-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deFlicker.m
44 lines (40 loc) · 956 Bytes
/
deFlicker.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function data=deFlicker(data,varargin)
%
%
defaults.flickerWindow = 10;
defaults.replaceBy = 'meanNeighbors';
defaults.repeat = 3;
defaults.sigmaMult = 2;
handle_defaults;
repeat;
for rrr=1:repeat
n = size(data,2);
for i=1:(floor(n/flickerWindow))
%if i==floor(n/flickerWindow)
% inds = (inds(end)+1):n;
%else
inds = (1:flickerWindow) + (i-1)*flickerWindow;
%end
slice = data(:,inds);
meds = repmat(median(slice,2),[1 flickerWindow]);
try
stad = repmat(sqrt(median((slice-meds).^2,2)),[1 flickerWindow]);
catch
keyboard
end
[qs,rs,vv] = find( sqrt((slice-meds).^2)>sigmaMult*stad);
for qi=1:length(qs)
q=qs(qi);
r=rs(qi);
switch r
case 1
slice(q,r) = slice(q,r+1);
case flickerWindow
slice(q,r) = slice(q,r-1);
otherwise
slice(q,r) = mean([slice(q,r+1) slice(q,r-1)]);
end
end
data(:,inds) = slice;
end
end