Subscript indices must either be real positive integers or logicals.
Error in lpr (line 304)
II=I2(row(p):row(p+1),column(q):column(q+1));
function [text] = lpr(name)
clc;
warning off;
name='2222.jpg';
I = imread (name);
I2=I;
k=1;
figure(k); imshow(I); k=k+1;
[m1 m2 m3]=size(I);
if m3>1
I = rgb2gray(I);
end
[rows cols] = size(I);
figure(k); imshow(I); k=k+1;
[m1 m2] = size(I);
for i=2:m1-1
for j=2:m2-1
if I(i,j)<50
I(i,j)=0;
end
if I2(i,j)<50
I2(i,j)=0;
end
end
end
for i=1:m1
for j=1:m2
if I(i,j)>200
I(i,j)=255;
end
if I2(i,j)>200
I2(i,j)=255;
end
end
end
figure(k); imshow(I); k=k+1;
Idilate = I;
for i = 1:rows
for j = 2:cols-1
temp = max(I(i,j-1), I(i,j));
Idilate(i,j) = max(temp, I(i,j+1));
end
end
I = Idilate;
difference = 0;
sum = 0;
total_sum = 0;
difference = uint32(difference);
disp('Processing Edges Horizontally...');
max_horz = 0;
maximum = 0;
for i = 2:cols
sum = 0;
for j = 2:rows
if(I(j, i) > I(j-1, i))
difference = uint32(I(j, i) - I(j-1, i));
else
difference = uint32(I(j-1, i) - I(j, i));
end
if(difference > 20)
sum = sum + difference;
end
horz1(i) = sum;
end
total_sum = total_sum + sum;
end
average = total_sum / cols;
figure(k);
plot (horz1);
title('Horizontal Edge Processing Histogram'); xlabel('Column Number ->');
ylabel('Difference ->');
k=k+1;
disp('Passing Horizontal Histogram through Low Pass Filter...');
sum = 0;
horz = horz1;
for i = 21:(cols-21) sum = 0;
for j = (i-20):(i+20)
sum = sum + horz1(j);
end
horz(i) = sum / 41;
end
subplot(3,1,2); plot (horz);
title('Horizontal Histogram after passing through Low Pass Filter');
xlabel('Column Number ->'); ylabel('Difference ->');
disp('Filter out Horizontal Histogram...');
for i = 1:cols
if(horz(i) < 1.2*average)
horz(i) = 0;
for j = 1:rows I(j, i) = 0;
end
end
end
subplot(3,1,3); plot (horz);
title('Horizontal Histogram after Filtering');
xlabel('Column Number ->');
ylabel('Difference ->');
figure(k); imshow(I); k=k+1;
total_sum = 0;
difference = uint32(difference);
disp('Processing Edges Vertically...');
maximum = 0;
max_vert = 0;
for i = 2:rows
sum = 0;
for j = 2:cols
if(I(i, j) > I(i, j-1))
difference = uint32(I(i, j) - I(i, j-1));
end
if(I(i, j) <= I(i, j-1))
difference = uint32(I(i, j-1) - I(i, j));
end
if(difference > 20)
sum = sum + difference;
end
vert1(i) = sum;
max_vert = i; maximum = sum;
end
total_sum = total_sum + sum;
end
average = total_sum / rows;
figure(k);
subplot(3,1,1); plot (vert1);
title('Vertical Edge Processing Histogram'); xlabel('Row Number ->');
ylabel('Difference ->');
k=k+1;
vert = vert1;
for i = 21:(rows-21)
sum = 0;
for j = (i-20):(i+20)
sum = sum + vert1(j);
end
vert(i) = sum / 41;
end
subplot(3,1,2); plot (vert);
title('Vertical Histogram after passing through Low Pass Filter');
xlabel('Row Number ->'); ylabel('Difference ->');
disp('Filter out Vertical Histogram...');
for i = 1:rows
if(vert(i) < 1.2*average)
vert(i) = 0;
for j = 1:cols
I(i, j) = 0;
end
end
end
subplot(3,1,3); plot (vert);
title('Histogram after Filtering');
xlabel('Row Number ->'); ylabel('Difference ->');
figure(k); imshow(I); k=k+1;
for i = 2:cols-2
if(horz(i) ~= 0 && horz(i-1) == 0 && horz(i+1) == 0)
column(j) = i;
column(j+1) = i; j = j + 2;
elseif((horz(i) ~= 0 && horz(i-1) == 0) || (horz(i) ~= 0 && horz(i+1) == 0))
column(j) = i; j = j+1;
end
end
j = 1;
for i = 2:rows-2
if(vert(i) ~= 0 && vert(i-1) == 0 && vert(i+1) == 0)
row(j) = i;
row(j+1) = i; j = j + 2;
elseif((vert(i) ~= 0 && vert(i-1) == 0) || (vert(i) ~= 0 && vert(i+1) == 0))
row(j) = i;
j = j+1;
end
end
[temp column_size] = size (column);
if(mod(column_size, 2))
column(column_size+1) = cols;
end
[temp row_size] = size (row);
if(mod(row_size, 2))
row(row_size+1) = rows;
end
for p = 1:2:row_size
for q = 1:2:column_size
II=I2(row(p):row(p+1),column(q):column(q+1));
II2=I(row(p):row(p+1),column(q):column(q+1));
[n1 n2] = size(II);
white=0;
for xx=1:n1
for yy=1:n2
if(II2(xx,yy)>240)
white=white+1;
end
end
end
ratio=white/(n1*n2);
if (n1>20 && n2>60 && ratio<0.8)
figure(k);
imshow(II);
k=k+1;
imwrite(II,'plate.jpg');
k=crop(k);
[k,text,flagm] = OCR(k);
end
if flagm
break;
end
end
end