2011-04-24 216 views
12

我需要知道如何在Matlab中對齊圖像以便進一步工作。如何對齊圖像 - Matlab

例如我有下一個車牌圖像,我想識別所有的數字 。

enter image description here

我的程序適用於直圖像,所以,我需要對齊圖像,然後 預製棒的光學識別系統。

該方法應該儘可能普遍適用於各種板和各種角度。

編輯:我試圖做到這一點與霍夫變換,但我沒有成功。任何人都可以幫助我做到這一點?

任何幫助將不勝感激。

+3

如果這是OpenCV的我會說找到最突出的近水平霍夫線,計算它的角度,然後用先前計算的角度對旋轉矩陣進行仿射變換。這是否有任何matlab等效?那麼你可能會發現它很有幫助。 – AruniRC 2011-04-24 14:02:14

回答

15

溶液首先在評價暗示通過@AruniRC,然後通過@belisarius Mathematica中實現。以下是我在MATLAB中的解釋。

這個想法基本上是一樣的:使用Canny方法檢測邊緣,使用Hough變換找到突出的線條,計算線角度,最後執行剪切變換以對齊圖像。

%# read and crop image 
I = imread('http://i.stack.imgur.com/CJHaA.png'); 
I = I(:,1:end-3,:);  %# remove small white band on the side 

%# egde detection 
BW = edge(rgb2gray(I), 'canny'); 

%# hough transform 
[H T R] = hough(BW); 
P = houghpeaks(H, 4, 'threshold',ceil(0.75*max(H(:)))); 
lines = houghlines(BW, T, R, P); 

%# shearing transforma 
slopes = vertcat(lines.point2) - vertcat(lines.point1); 
slopes = slopes(:,2) ./ slopes(:,1); 
TFORM = maketform('affine', [1 -slopes(1) 0 ; 0 1 0 ; 0 0 1]); 
II = imtransform(I, TFORM); 

現在讓我們看看結果

%# show edges 
figure, imshow(BW) 

%# show accumlation matrix and peaks 
figure, imshow(imadjust(mat2gray(H)), [], 'XData',T, 'YData',R, 'InitialMagnification','fit') 
xlabel('\theta (degrees)'), ylabel('\rho'), colormap(hot), colorbar 
hold on, plot(T(P(:,2)), R(P(:,1)), 'gs', 'LineWidth',2), hold off 
axis on, axis normal 

%# show image with lines overlayed, and the aligned/rotated image 
figure 
subplot(121), imshow(I), hold on 
for k = 1:length(lines) 
    xy = [lines(k).point1; lines(k).point2]; 
    plot(xy(:,1), xy(:,2), 'g.-', 'LineWidth',2); 
end, hold off 
subplot(122), imshow(II) 

canny_edges hough_transform lines_overlayed_image_aligned

+0

夢幻般的答案。謝謝Amro。 +1。 – rayryeng 2015-11-19 22:46:57

3

如果您正在使用某種機器學習工具箱進行文字識別,請嘗試從所有印版中學習 - 不僅僅是對齊的。識別結果應該同樣好,如果你改變了平板或者不要,因爲通過變換,根據真實數字的新信息不會增強圖像。

0

如果所有圖像都有像這樣的深色背景,可以對圖像進行二值化,將線條放在明亮區域的頂部或底部,然後根據線條漸變計算仿射投影矩陣。

+0

感謝您的回答。我正在對所有圖像進行二值化,所以是的背景會是這樣的。我如何適應線條? – 2011-05-12 13:37:46

6

在數學,使用邊緣檢測和Hough變換:

enter image description here

+0

感謝您的回答。你知道如何在Matlab中做到這一點?我的Matlab技能​​不太好... – 2011-06-05 08:41:38

+2

@Michael對不起,這裏沒有Matlab。但是你得到了關鍵字:Hough變換,邊緣檢測,剪切變換。 – 2011-06-06 14:24:50

+1

@Michael,@belisarius:我發佈了一個MATLAB的解決方案,受此啓發 – Amro 2011-07-03 15:31:16