MATLAB:使用行投影直方图

时间:2016-02-29 11:54:06

标签: matlab image-processing histogram crop projection

我是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');

在梯度计算之后,我计算了以下直方图:

Horizontal Projection Histogram of the image

现在我需要根据论文中给出的标准裁剪车牌:

Cropping Step shown in the research paper

但我不知道如何根据水平投影直方图裁剪图像?

我已在mathworksstackoverflow上阅读了一些答案,但找不到有关我的问题的任何指导。有人请指导我如何裁剪水平区域,如图所示。提前谢谢。

1 个答案:

答案 0 :(得分:0)

描述说明&#34;垂直渐变的水平投影&#34; 。你在计算投影之前计算了垂直梯度吗?

从图像的外观来看,我认为你可能从另一个类似的问题here中错过了这一步。