Before proceeding with the CCA for regions E and A, it is fundamental to find the
parameter limits (just as in post # 30). The two parameters at hand are the
orientation angle and the height of the character in each region.
The code for
detecting the orientation angle limits is:
% Detecting Orientation Angles of Segmented Characters in LP
% This program detects the orientation angle of each of the segmented
% characters five studied license plates. First, the objects in each image
% is labelled with bwlabel (classical approach of connected component
% labeling with 8-connectivity), then the labeled matrix identifying the
% boarders of the license plates is used for calculating the orientation
% angle of the segmented characters,. This is calculated according to the
% equation:
% tan(phi_i) = 2[r_sum(c_sum(rcWi(r,c))]/[r_sum(c_sum(r^2Wi(r,c)) -
% r_sum(c_sum(c^2Wi(r,c))]
clear all
clc
ob_cnt = 0;
% Generating Gaussian mask to be used for blurring thresholded picture
% before performing object labeling
% sig = fix(randn*10); % Generating gradient of Gaussian masks for filtering
% % along x-axis (fx) and y-axis (fy)
% while (sig == 0)||(mod(sig,2)==0)||(abs(sig)>5)
% sig = fix(randn*10); % Ensure that masks formed are odd matrices
% end % each of whose size is no greater than 15x15
% sig = abs(sig); % Sigma should be positive
% After generating several Gaussian masks, best result obtained for sig = 1
sig = 1;
n = 3*sig;
for i=1:n
for j=1:n
g(i,j) = exp(-(i^2+j^2)/2*sig^2);
end
end
figure(ob_cnt+1)
I1 = imread('image 1.jpg'); % Importing picture of license plate 1
I1 = rgb2gray(I1);
imshow(I1,[]); % Show grayscale picture
[M1,N1] = size(I1);
figure(ob_cnt+2)
I_bin1 = edge(I1,'canny'); % Performing edge detection with Canny method
imshow(I_bin1,[]); % Show edge detection
figure(ob_cnt+3)
f1 = conv2(double(I_bin1),double(g));
f1 = f1(1:M1,1:N1);
[W1,num1] = bwlabel(f1,8); % Labeling with Matlab command bwlabel
imshow(W1,[]);
figure(ob_cnt+4)
% Extracting LP from middle section where expected to be
LP1 = W1(600:910,990:1500);
imshow(LP1,[]);
[M1,N1] = size(LP1);
for i = 1:M1
for j = 1:N1
rc_component1(i,j) = i*j*LP1(i,j);
end
end
for i = 1:M1
for j = 1:N1
r2_component1(i,j) = i^2*LP1(i,j);
end
end
for i = 1:M1
for j = 1:N1
c2_component1(i,j) = j^2*LP1(i,j);
end
end
phi1 = atand((2*sum(sum(rc_component1)))/...
(sum(sum(r2_component1))-sum(sum(c2_component1))))
%--------------------------------------------------------------------------
ob_cnt = ob_cnt + 4;
figure(ob_cnt+1)
I2 = imread('image 2.jpg'); % Importing picture of license plate 2
I2 = rgb2gray(I2);
imshow(I2,[]); % Show grayscale picture
[M2,N2] = size(I2);
figure(ob_cnt+2)
I_bin2 = edge(I2,'canny'); % Performing edge detection with Canny method
imshow(I_bin2,[]); % Show edge detection
figure(ob_cnt+3)
f2 = conv2(double(I_bin2),double(g));
f2 = f2(1:M2,1:N2);
[W2,num2] = bwlabel(f2,8); % Labeling with Matlab command bwlabel
imshow(W2,[]);
figure(ob_cnt+4)
% Extracting LP from middle section where expected to be
LP2 = W2(750:1100,900:1650);
imshow(LP2,[]);
[M2,N2] = size(LP2);
for i = 1:M2
for j = 1:N2
rc_component2(i,j) = i*j*LP2(i,j);
end
end
for i = 1:M2
for j = 1:N2
r2_component2(i,j) = i^2*LP2(i,j);
end
end
for i = 1:M2
for j = 1:N2
c2_component2(i,j) = j^2*LP2(i,j);
end
end
phi2 = atand((2*sum(sum(rc_component2)))/...
(sum(sum(r2_component2))-sum(sum(c2_component2))))
%--------------------------------------------------------------------------
ob_cnt = ob_cnt + 4;
figure(ob_cnt+1)
I3 = imread('image 3.jpg'); % Importing picture of license plate 3
I3 = rgb2gray(I3);
imshow(I3,[]); % Show grayscale picture
[M3,N3] = size(I3);
figure(ob_cnt+2)
I_bin3 = edge(I3,'canny'); % Performing edge detection with Canny method
imshow(I_bin3,[]); % Show edge detection
figure(ob_cnt+3)
f3 = conv2(double(I_bin3),double(g));
f3 = f3(1:M3,1:N3);
[W3,num3] = bwlabel(f3,8); % Labeling with Matlab command bwlabel
imshow(W3,[]);
figure(ob_cnt+4)
% Extracting LP from middle section where expected to be
LP3 = W3(700:1100,1100:1700);
imshow(LP3,[]);
[M3,N3] = size(LP3);
for i = 1:M3
for j = 1:N3
rc_component3(i,j) = i*j*LP3(i,j);
end
end
for i = 1:M3
for j = 1:N3
r2_component3(i,j) = i^2*LP3(i,j);
end
end
for i = 1:M3
for j = 1:N3
c2_component3(i,j) = j^2*LP3(i,j);
end
end
phi3 = atand((2*sum(sum(rc_component3)))/...
(sum(sum(r2_component3))-sum(sum(c2_component3))))
%--------------------------------------------------------------------------
ob_cnt = ob_cnt + 4;
figure(ob_cnt+1)
I4 = imread('image 4.jpg'); % Importing picture of license plate 4
I4 = rgb2gray(I4);
imshow(I4,[]); % Show grayscale picture
[M4,N4] = size(I4);
figure(ob_cnt+2)
I_bin4 = edge(I4,'canny'); % Performing edge detection with Canny method
imshow(I_bin4,[]); % Show edge detection
figure(ob_cnt+3)
f4 = conv2(double(I_bin4),double(g));
f4 = f4(1:M4,1:N4);
[W4,num4] = bwlabel(f4,8); % Labeling with Matlab command bwlabel
imshow(W4,[]);
figure(ob_cnt+4)
% Extracting LP from middle section where expected to be
LP4 = W4(620:1020,1000:1650);
imshow(LP4,[]);
[M4,N4] = size(LP4);
for i = 1:M4
for j = 1:N4
rc_component4(i,j) = i*j*LP4(i,j);
end
end
for i = 1:M4
for j = 1:N4
r2_component4(i,j) = i^2*LP4(i,j);
end
end
for i = 1:M4
for j = 1:N4
c2_component4(i,j) = j^2*LP4(i,j);
end
end
phi4 = atand((2*sum(sum(rc_component4)))/...
(sum(sum(r2_component4))-sum(sum(c2_component4))))
%--------------------------------------------------------------------------
ob_cnt = ob_cnt + 4;
figure(ob_cnt+1)
I5 = imread('image 5.jpg'); % Importing picture of license plate 5
I5 = rgb2gray(I5);
imshow(I5,[]); % Show grayscale picture
[M5,N5] = size(I5);
figure(ob_cnt+2)
I_bin5 = edge(I5,'canny'); % Performing edge detection with Canny method
imshow(I_bin5,[]); % Show edge detection
figure(ob_cnt+3)
f5 = conv2(double(I_bin5),double(g));
f5 = f5(1:M5,1:N5);
[W5,num5] = bwlabel(f5,8); % Labeling with Matlab command bwlabel
imshow(W5,[]);
figure(ob_cnt+4)
% Extracting LP from middle section where expected to be
LP5 = W5(600:1100,710:1850);
imshow(LP5,[]);
[M5,N5] = size(LP5);
for i = 1:M5
for j = 1:N5
rc_component5(i,j) = i*j*LP5(i,j);
end
end
for i = 1:M5
for j = 1:N5
r2_component5(i,j) = i^2*LP5(i,j);
end
end
for i = 1:M5
for j = 1:N5
c2_component5(i,j) = j^2*LP5(i,j);
end
end
phi5 = atand((2*sum(sum(rc_component5)))/...
(sum(sum(r2_component5))-sum(sum(c2_component5))))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The code for
detecting the height limits is:
% Detecting Aspect Ratios of LP
% This program detects the height of each of the five studied license
% plates. First, the objects in each image is labelled with bwlabel
% (classical approach of connected component labeling with 8-connectivity),
% then the label(s) identifying the boarders of the license plates are
% used to extract the position coordinates. The height is then
% calculated according to the equation: rmax - rmin + 1.
clear all
clc
ob_cnt = 0;
% Generating Gaussian mask to be used for blurring thresholded picture
% before performing object labeling
% sig = fix(randn*10); % Generating gradient of Gaussian masks for filtering
% % along x-axis (fx) and y-axis (fy)
% while (sig == 0)||(mod(sig,2)==0)||(abs(sig)>5)
% sig = fix(randn*10); % Ensure that masks formed are odd matrices
% end % each of whose size is no greater than 15x15
% sig = abs(sig); % Sigma should be positive
% After generating several Gaussian masks, best result obtained for sig = 1
sig = 1;
n = 3*sig;
for i=1:n
for j=1:n
g(i,j) = exp(-(i^2+j^2)/2*sig^2);
end
end
figure(ob_cnt+1)
I1 = imread('image 1.jpg'); % Importing picture of license plate 1
I1 = rgb2gray(I1);
imshow(I1,[]); % Show grayscale picture
[M1,N1] = size(I1);
figure(ob_cnt+2)
I_bin1 = edge(I1,'canny'); % Performing edge detection with Canny method
imshow(I_bin1,[]); % Show edge detection
figure(ob_cnt+3)
f1 = conv2(double(I_bin1),double(g));
f1 = f1(1:M1,1:N1);
[W1,num1] = bwlabel(f1,8); % Labeling with Matlab command bwlabel
imshow(W1,[]);
figure(ob_cnt+4)
% Extracting LP from middle section where expected to be
imshow(W1(600:910,990:1500),[]);
figure(ob_cnt+5)
% Extracting character from LP
CS1 = W1(660:720,1080:1110);
imshow(CS1,[]);
r1_max = 720;
r1_min = 660;
h1 = r1_max - r1_min + 1
%--------------------------------------------------------------------------
ob_cnt = ob_cnt + 5;
figure(ob_cnt+1)
I2 = imread('image 2.jpg'); % Importing picture of license plate 2
I2 = rgb2gray(I2);
imshow(I2,[]); % Show grayscale picture
[M2,N2] = size(I2);
figure(ob_cnt+2)
I_bin2 = edge(I2,'canny'); % Performing edge detection with Canny method
imshow(I_bin2,[]); % Show edge detection
figure(ob_cnt+3)
f2 = conv2(double(I_bin2),double(g));
f2 = f2(1:M2,1:N2);
[W2,num2] = bwlabel(f2,8); % Labeling with Matlab command bwlabel
imshow(W2,[]);
figure(ob_cnt+4)
% Extracting LP from middle section where expected to be
imshow(W2(750:1100,900:1650),[]);
figure(ob_cnt+5)
% Extracting character from LP
CS2 = W2(780:880,1170:1210);
imshow(CS2,[]);
r2_max = 880;
r2_min = 780;
h2 = r2_max - r2_min + 1
%--------------------------------------------------------------------------
ob_cnt = ob_cnt + 5;
figure(ob_cnt+1)
I3 = imread('image 3.jpg'); % Importing picture of license plate 3
I3 = rgb2gray(I3);
imshow(I3,[]); % Show grayscale picture
[M3,N3] = size(I3);
figure(ob_cnt+2)
I_bin3 = edge(I3,'canny'); % Performing edge detection with Canny method
imshow(I_bin3,[]); % Show edge detection
figure(ob_cnt+3)
f3 = conv2(double(I_bin3),double(g));
f3 = f3(1:M3,1:N3);
[W3,num3] = bwlabel(f3,8); % Labeling with Matlab command bwlabel
imshow(W3,[]);
figure(ob_cnt+4)
% Extracting LP from middle section where expected to be
imshow(W3(700:1100,1100:1700),[]);
figure(ob_cnt+5)
% Extracting character from LP
CS3 = W3(785:870,1270:1340);
imshow(CS3,[]);
r3_max = 870;
r3_min = 785;
h3 = r3_max - r3_min + 1
%--------------------------------------------------------------------------
ob_cnt = ob_cnt + 5;
figure(ob_cnt+1)
I4 = imread('image 4.jpg'); % Importing picture of license plate 4
I4 = rgb2gray(I4);
imshow(I4,[]); % Show grayscale picture
[M4,N4] = size(I4);
figure(ob_cnt+2)
I_bin4 = edge(I4,'canny'); % Performing edge detection with Canny method
imshow(I_bin4,[]); % Show edge detection
figure(ob_cnt+3)
f4 = conv2(double(I_bin4),double(g));
f4 = f4(1:M4,1:N4);
[W4,num4] = bwlabel(f4,8); % Labeling with Matlab command bwlabel
imshow(W4,[]);
figure(ob_cnt+4)
% Extracting LP from middle section where expected to be
imshow(W4(620:1020,1000:1650),[]);
figure(ob_cnt+5)
% Extracting character from LP
CS4 = W4(675:770,1190:1260);
imshow(CS4,[]);
r4_max = 770;
r4_min = 675;
h4 = r4_max - r4_min + 1
%--------------------------------------------------------------------------
ob_cnt = ob_cnt + 5;
figure(ob_cnt+1)
I5 = imread('image 5.jpg'); % Importing picture of license plate 5
I5 = rgb2gray(I5);
imshow(I5,[]); % Show grayscale picture
[M5,N5] = size(I5);
figure(ob_cnt+2)
I_bin5 = edge(I5,'canny'); % Performing edge detection with Canny method
imshow(I_bin5,[]); % Show edge detection
figure(ob_cnt+3)
f5 = conv2(double(I_bin5),double(g));
f5 = f5(1:M5,1:N5);
[W5,num5] = bwlabel(f5,8); % Labeling with Matlab command bwlabel
imshow(W5,[]);
figure(ob_cnt+4)
% Extracting LP from middle section where expected to be
imshow(W5(600:1100,710:1850),[]);
figure(ob_cnt+5)
% Extracting character from LP
CS5 = W5(815:945,970:1025);
imshow(CS5,[]);
r5_max = 945;
r5_min = 815;
h5 = r5_max - r5_min + 1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
An example of a segmented character would be: