forked from ludles/OralScreen
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathedge_width.m
206 lines (191 loc) · 6.76 KB
/
edge_width.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
function [local,contrast] = edge_width(ori_img)
% Syntax:[local,contrast] = edge_width(ori_img)
% use edge model to compute the width of each edge pixel.
%
% ori_image is the image to be processed.
% local is a matrix of the same size of the ori_img. Value of each point
% represents the computed edge width of each detected edge point(A point
% belongs to an edge).
% contrast is a matrix of the same size of the ori_img. Value of each point
% represents the computed contrast of each detected edge point(A point
% belongs to an edge).
%
% Reference:
% Guan J, Zhang W, Gu J, et al. No-reference Blur Assessment Based on Edge
% Modeling[J]. Journal of Visual Communication and Image Representation,
% 2015.
ori_img = double(ori_img);
[m,n] = size(ori_img);
sigma=0.72;
ssq = sigma^2;
width = 7;
t = (-width:width);
%gau = exp(-(t..*t)/(2*ssq))/(2*pi*ssq); % the gaussian 1D filter
[x,y]=meshgrid(-width:width,-width:width);
dgau2D=-y.*exp(-(x.*x+y.*y)/(2*ssq))/(2*pi*ssq.*ssq);
dgau2D=dgau2D';
[Tmp_x,Tmp_y,Sum_x,Sum_y,X_detect,Y_detect,XXX] = mag2(ori_img,dgau2D);
X_detect=X_detect';
Y_detect=Y_detect';
mag = sqrt((X_detect.*X_detect) + (Y_detect.*Y_detect));
PI = 3.1415929;
PI2 = 1.5707965;
EDGE = 255;
SHADE = 0;
MID = 100;
m_min_gradient = 13.6 ;
width_points = zeros(m, n);
edge_q = zeros(m, n);
edge_c = zeros(m, n);
for i = 2: m-1
for j = 2: n-1
detect(i,j)=0;
if abs(mag(i,j)) > m_min_gradient.*0.5
u=X_detect(i,j);
v=Y_detect(i,j);
if v == 0.0
if u > 0.0
edge_q(i,j)=0.0;
o=mag(i-1,j);
p=mag(i+1,j);
else
edge_q(i,j)=PI;
o=mag(i+1,j);
p=mag(i-1,j);
end
else if u == 0
if v > 0.0
edge_q(i,j) = 0.5.*PI;
o=mag(i,j-1);
p=mag(i,j+1);
else
edge_q(i,j) = -0.5.*PI;
o=mag(i,j+1);
p=mag(i,j-1);
end
else if (u.*v) > 0.0
q=v/u;
if u > 0.0
edge_q(i,j) = atan(q);
% if 1<i<m
if q <= 1.0
o=q.*mag(i-1,j-1)+(1.0-q).*mag(i-1,j);
p=q.*mag(i+1,j+1)+(1.0-q).*mag(i+1,j);
else
q=1.0/q;
o=q.*mag(i-1,j-1)+(1.0-q).*mag(i,j-1);
p=q.*mag(i+1,j+1)+(1.0-q).*mag(i,j+1);
end
else
edge_q(i,j)=atan(q)-PI;
if q<=1.0
o=q.*mag(i+1,j+1)+(1.0-q).*mag(i+1,j);
p=q.*mag(i-1,j-1)+(1.0-q).*mag(i-1,j);
else
q=1.0/q;
o=q.*mag(i+1,j+1)+(1.0-q).*mag(i,j+1);
p=q.*mag(i-1,j-1)+(1.0-q).*mag(i,j-1);
end
end
else
q=abs(v/u);
if u > 0
edge_q(i,j)=-1.0.*atan(q);
if q <= 1.0
o=q.*mag(i-1,j+1)+(1.0-q).*mag(i-1,j);
p=q.*mag(i+1,j-1)+(1.0-q).*mag(i+1,j);
else
q=1.0/q;
o=q.*mag(i-1,j+1)+(1.0-q).*mag(i,j+1);
p=q.*mag(i+1,j-1)+(1.0-q).*mag(i,j-1);
end
else
edge_q(i,j)=PI-atan(q);
if q <= 1.0
o=q.*mag(i+1,j-1)+(1.0-q).*mag(i+1,j);
p=q.*mag(i-1,j+1)+(1.0-q).*mag(i-1,j);
else
q=1.0/q;
o=q.*mag(i+1,j-1)+(1.0-q).*mag(i,j-1);
p=q.*mag(i-1,j+1)+(1.0-q).*mag(i,j+1);
end
end
end
end
end
if mag(i,j) >= o && mag(i,j) >= p
if abs(mag(i,j))>m_min_gradient
detect(i,j)=EDGE;
else
detect(i,j)=MID;
end
d1=mag(i,j);
d2=o;
d3=p;
if d3<1e-10
d3=1e-10;
end
if d2<1e-10
d2=1e-10;
end
if abs( edge_q(i,j)) == PI2
q=0.0;
else if edge_q(i,j)==0.0|| edge_q(i,j)==PI
q=0.0;
else
q=abs(tan( edge_q(i,j)));
if q > 1.0
q=1.0/q;
end
end
end
p=log(d1.*d1/d2/d3);
u=sqrt(1.0+q.*q);
% a = 1;
m_sigmad=sigma;
v=(u.*u/p-m_sigmad.*m_sigmad);
if v<0.0
v=0.01;
end
width_points(i,j)=sqrt(v);
w=power((d2/d3),(0.25/u));
t=sqrt(2.0*PI*u*u/p);
edge_c(i,j)=d1*t*w;
end
end
end
end
for i=1:m
for j=1:n
if width_points(i,j)>= 14;
width_points(i,j) = 0;
edge_c(i,j) = 0;
end
end
end
for i=1:m
for j=1:n
if edge_c(i,j)>=255
width_points(i,j) = 0;
edge_c(i,j) = 0;
end
end
end
for i=1:m
for j=1:n
if width_points(i,j)<= 0.2;
width_points(i,j) = 0;
edge_c(i,j) = 0;
end
end
end
for i=1:m
for j=1:n
if edge_c(i,j)<=8 % Threshold C_T
width_points(i,j) = 0;
edge_c(i,j) = 0;
end
end
end
local = width_points;
contrast = edge_c;