forked from 13shivang/alpr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feature_vector.m
112 lines (100 loc) · 2.7 KB
/
feature_vector.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
function [a] = feature_vector( I )
z=(feature1(I));
I=imresize(I,[42 24]);
holes=hole(I);
I_ori=I;
I = padarray(I,[2 2],'both');
I=imfill(I,'holes');
se = strel('disk',3);
I = imerode(I,se);
% figure();imshow(I);
%%%%%%%%%%%%%%%%%%%%%%HORIZONTAL LINE DETECTION%%%%%%%%%%%%%%%%%%%%%%%%
[~,ang]=imgradient(I);
ang=round(ang);
%Blakens the pixels with angles other than -90 or 90 as horizontal lines
%are at 90 degree
for i=1:46
for j=1:28
if(ang(i,j)==90||ang(i,j)==-90)
I_hori(i,j)=255;
else
I_hori(i,j)=0;
end
end
end
I_hori=bwareaopen(I_hori,15); %Removes small unwanted pixels
%figure();imshow(I_hori);
se = strel('disk',3);
I_hori = imclose(I_hori,se);
%figure();imshow(I_hori);
[L,hori] = bwlabel(I_hori); %counts the horizontal lines
%%%%%%%%%%%%%%%%%%%%%%%VERTICAL LINE DETECTION%%%%%%%%%%%%%%%%%%%%%%%%
I_verti=rot90(I,-1); %Rotates image by 90 in anti-clock wise sense and
%then detecting horizontal lines
[~,ang1]=imgradient(I_verti);
ang1=round(ang1);
%Blakens the pixels with angles other than -90 or 90 as horizontal lines
%are at 90 degree
for i=1:28
for j=1:46
if(ang1(i,j)==90||ang1(i,j)==-90)
I_verti(i,j)=255;
else
I_verti(i,j)=0;
end
end
end
I_verti=rot90(I_verti); %Rotating the image by 90 in clockwise direction
se = strel('disk',1);
I_verti = imclose(I_verti,se);
%figure();imshow(I_verti);
I_verti=bwareaopen(I_verti,24); %Removes small unwanted pixels
%figure();imshow(I_verti);
se = strel('disk',5);
I_verti = imclose(I_verti,se);
%figure();imshow(I_verti);
[L,verti] = bwlabel(I_verti);
I=I_ori;
approx = imresize(I, [7 4]);
approx = reshape(approx, [1 28]);
[~,ang]=imgradient(I);
ang=round(ang);
%r=/
%l=\
temp_l1=0;
temp_l2=0;
temp_r1=0;
temp_r2=0;
l=0;
r=0;
for i=1:42
for j=1:24
if((ang(i,j)>20 && ang(i,j)<=45)|(ang(i,j)>-160 && ang(i,j)<=-135))
temp_l1=temp_l1+1;
elseif((ang(i,j)>45 && ang(i,j)<=70)|(ang(i,j)>-135 && ang(i,j)<=-110))
temp_l2=temp_l2+1;
end
if((ang(i,j)<-20 && ang(i,j)>=-45)|(ang(i,j)<160 && ang(i,j)>=135))
temp_r1=temp_r1+1;
elseif((ang(i,j)<-45 && ang(i,j)>=-70)|(ang(i,j)<135 && ang(i,j)>=110))
temp_r2=temp_r2+1;
end
end
end
% temp_l1
% temp_l2
%
% temp_r1
% temp_r2
if(temp_l1>45|temp_l2>45|temp_r1>45|temp_r2>45)
if(abs(temp_l1-temp_r1)<20)
l=1;
r=1;
elseif((temp_l1>temp_r1)&&temp_l1>40)
l=1;
elseif((temp_l1<temp_r1)&&temp_r1>40)
r=1;
end
end
a =transpose( [ holes verti hori r l z ]);
end