2
我是Matlab
的初学者,我试图实现一篇ANPR Parking System
的研究论文,该论文使用行投影直方图来识别牌照的水平区域。我已经写下面的代码,用于计算垂直梯度:MATLAB:使用行投影直方图对图像进行裁剪
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的一些答案,但找不到有关我的问题的任何指导。有人请指导我如何裁剪水平区域,如图所示。提前致谢。
对不起,我不明白这个答案是否有助于**使用直方图**裁剪图像。我想我没有错过这一步。请查看更新后的问题,我已将前面的步骤添加到我的问题中。 –
好吧,首先我不确定你的意思是直方图在这里。直方图为您提供有关图像的信息,与像素的位置无关。只是他们的价值。现在当你说水平投影时,基本上意味着每列中所有像素的总和。 (我也使用过这种变化,有时它会更好一些)。所以一旦你进行水平投影,你会得到一个向量。这个矢量将帮助您识别号码牌的裁剪点。 –