I am a beginner in Matlab
and I am trying to implement a research paper of ANPR Parking System
which uses the row projection histogram to identify the horizontal region of the license plates. I have written the following code for calculating the vertical gradients:
Matlab Code:
[rows,cols] = size(img);
img2 = zeros(rows,cols);
%Calculated the gradients
for i =1:1:rows
for j =1:1:cols-1
img2(i,j) = abs(img(i,j+1) - img(i,j));
end
end
% calculated the mean of gradients to determine which pixels hold the value
% that is above the average difference as the paper says `Then the average
% gradient variance is calculated and compared with each other. The bigger
% intensity variations provide the rough estimation of license plate region.`
M = mean2(img2);
for i =1:1:rows
for j =1:1:cols-1
if(abs(img(i,j+1) - img(i,j))<M)
img2(i,j)=0;
else
img2(i,j)=100;
end
end
end
% Applied average filter to reduce the noise
img2 = filter2(fspecial('average',2),img2)/255;
% Output is shown
figure,imshow(img2);title('Gradient');
After the gradients calculation, I computed the following histogram:
Now I need to crop the license plate according to the criteria given in the paper:
But I don't know how to crop the image on the basis of the horizontal projection histogram?
I have read some Answers on mathworks and stackoverflow but couldn't find any guidance regarding my issue. Someone please guide me what I need to do to crop the horizontal area as shown in the image. Thanks in advance.