2016-02-29 185 views
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'); 

梯度計算之後,我計算以下直方圖:

Horizontal Projection Histogram of the image

現在我需要根據論文中給出的標準裁剪車牌:

Cropping Step shown in the research paper

但我不知道如何在水平投影直方圖的基礎上裁剪圖像?

我已閱讀mathworksstackoverflow的一些答案,但找不到有關我的問題的任何指導。有人請指導我如何裁剪水平區域,如圖所示。提前致謝。

回答

0

說明文字說「垂直梯度水平投影」。計算投影之前您是否計算了垂直梯度?

從圖像的外觀我認爲你可能錯過了這一步從另一個類似的問題here

+0

對不起,我不明白這個答案是否有助於**使用直方圖**裁剪圖像。我想我沒有錯過這一步。請查看更新後的問題,我已將前面的步驟添加到我的問題中。 –

+0

好吧,首先我不確定你的意思是直方圖在這裏。直方圖爲您提供有關圖像的信息,與像素的位置無關。只是他們的價值。現在當你說水平投影時,基本上意味着每列中所有像素的總和。 (我也使用過這種變化,有時它會更好一些)。所以一旦你進行水平投影,你會得到一個向量。這個矢量將幫助您識別號碼牌的裁剪點。 –