簡體   English   中英

如何對齊圖像 - Matlab

[英]How to align image - Matlab

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

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

在此處輸入圖片說明

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

該方法應盡可能適用於各種板材和各種角度。

編輯:我試圖用霍夫變換來做到這一點,但我沒有成功。 有人可以幫我做這個嗎?

任何幫助將不勝感激。

該解決方案首先由@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_edgeshough_transformlines_overlayed_image_aligned

在 Mathematica 中,使用邊緣檢測和霍夫變換:

在此處輸入圖片說明

如果您使用某種機器學習工具箱進行文本識別,請嘗試從所有板塊中學習 - 不僅僅是對齊的板塊。 如果你變換盤子或不變換盤子,識別結果應該同樣好,因為通過變換,沒有根據真實數字的新信息來增強圖像。

如果所有圖像都有這樣的暗背景,您可以對圖像進行二值化,將線條擬合到明亮區域的頂部或底部,並根據線條梯度計算仿射投影矩陣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM