-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpreprocess_I_2.m
64 lines (45 loc) · 1.36 KB
/
preprocess_I_2.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function I = preprocess_I_2(I,k,nn,V)
if mod(k,2) == 0
l = round(k/2);
u = l+1;
else
l = round(k/2);
u = l;
end
% In = imclose(imdilate(edge(I),strel(ones(10,10))),strel(ones(10,10)));
In = imdilate(edge(I),strel('sphere',V));
In = imfill(medfilt2(In - imopen(In - (I~=0),strel('sphere',4)),[5 5]));
for i = 1:size(I,1)
for j = 1:size(I,2)
if(In(i,j) ~= 0 && I(i,j) == 0)
n = 0;
s = 0;
mm = [];
ll = [];
for ii = i-u:i+l
for jj = j-u:j+l
if(ii > size(I,1) || jj > size(I,2))
continue;
end
if(I(ii,jj) ~= 0)
mm(n+1) = I(ii,jj);
ll(n+1,1) = ii;
ll(n+1,2) = jj;
s = s + double(I(ii,jj));
n = n + 1;
end
end
end
if( size(mm,2) > 3)
I(i,j) = round(get_n_near_pts(mm,ll, i,j,nn));
% mmm = max(mm(:));
else
% if(size(mmm,1) ~= 0)
% I(i,j) = mmm;
% end
I(i,j) = round(s/n);
end
end
end
end
end