forked from abhijeet-talaulikar/An-Enhanced-Approach-for-Detecting-Helmet-on-Motorcyclists-Using-Image-Processing-and-ML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharc_circularity.m
45 lines (45 loc) · 1.21 KB
/
arc_circularity.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
function [ac] = arc_circularity(I, Quadrant)
if ismember(Quadrant,[1 2]) == 0
return;
elseif Quadrant == 2
I = I(:,end:-1:1,:);
end
y = size(I,1);
x = size(I,2);
ox = 1; %origin x coord
oy = size(I,1); %origin y coord
maxBlobWidth = 0;
for i = 1:x
if I(y,i)==1
break;
end
maxBlobWidth = maxBlobWidth + 1;
end
radii = zeros(1,maxBlobWidth);
for i = 1:maxBlobWidth
%if first pixel is black
if I(size(I,1),i)==0
for j = size(I,1):-1:1
if I(j,i)==1
break;
end
end
radii(1,i) = sqrt(( (i-ox)^2)+( (j-oy)^2));
else
%if first pixel is white then loop till lowermost black pixel and
%then run same algo as above
for k = size(I,1):-1:1
if I(k,i)==0
break;
end
end
for j = k:-1:1
if I(j,i)==1
break;
end
end
radii(1,i) = sqrt(( (i-ox)^2)+( (j-oy)^2));
end
end
ac = mean(radii) / std(radii);
end