我是Matlab
的初学者,我正在尝试实施ANPR Parking System
的研究论文,该论文使用行投影直方图来识别车牌的水平区域。我编写了以下用于计算垂直渐变的代码:
Matlab代码:
[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');
在梯度计算之后,我计算了以下直方图:
现在我需要根据论文中给出的标准裁剪车牌:
但我不知道如何根据水平投影直方图裁剪图像?
我已在mathworks和stackoverflow上阅读了一些答案,但找不到有关我的问题的任何指导。有人请指导我如何裁剪水平区域,如图所示。提前谢谢。