简体   繁体   English

MATLAB:使用行投影直方图裁剪图像

[英]MATLAB: Crop an image using Row Projection Histogram

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. 我是Matlab的初学者,我正在尝试实施ANPR Parking System的研究论文,该论文使用行投影直方图来识别车牌的水平区域。 I have written the following code for calculating the vertical gradients: 我编写了以下代码来计算垂直渐变:

Matlab Code: 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');

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. 我已经阅读了有关mathworksstackoverflow的一些解答,但是找不到关于我的问题的任何指导。 Someone please guide me what I need to do to crop the horizontal area as shown in the image. 有人请指导我如何裁剪图像中的水平区域,如图所示。 Thanks in advance. 提前致谢。

The discription says "horizontal projection of vertical gradient" . 标题上写着“垂直梯度的水平投影” Did you compute the vertical gradient before computing the projection ? 在计算投影之前,您是否已计算出垂直梯度?

From the looks of the image i think you might have missed this step from another similar question here . 从图像的外观我想你可能会错过从另一个类似的问题,这一步在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM