【问题标题】:How to align image - Matlab如何对齐图像 - Matlab
【发布时间】:2011-08-11 20:46:20
【问题描述】:

我需要知道如何在 Matlab 中对齐图像以进行进一步的工作。

例如,我有下一张车牌图像,我想识别所有 数字。

我的程序适用于直图像,所以我需要对齐图像,然后 预制光学识别系统。

该方法应尽可能通用,适用于各种板和各种角度。

编辑:我尝试使用霍夫变换来做到这一点,但我没有成功。有人可以帮我做这件事吗?

任何帮助将不胜感激。

【问题讨论】:

  • 如果这是 OpenCV,我会说找到最突出的近水平霍夫线,计算它的角度,然后使用具有先前计算的角度的旋转矩阵进行仿射变换。这有任何matlab等价物吗?那么您可能会发现它很有帮助。

标签: matlab image-processing computer-vision alignment


【解决方案1】:

解决方案首先由 cmets 中的 @AruniRC 暗示,然后由 Mathematica 中的 @belisarius 实施。以下是我在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)

【讨论】:

  • 很棒的答案。谢谢阿姆罗。 +1。
【解决方案2】:

在 Mathematica 中,使用边缘检测和霍夫变换:

【讨论】:

  • 感谢您的回答。你知道如何在 Matlab 中做到这一点吗?我的 Matlab 技能不太好......
  • @Michael 抱歉,这里没有 Matlab。但是你得到了关键词:霍夫变换、边缘检测、剪切变换。
  • @Michael, @belisarius:我在 MATLAB 中发布了一个受此启发的解决方案
【解决方案3】:

如果所有图像都有类似的暗背景,您可以对图像进行二值化,将线条拟合到明亮区域的顶部或底部,并根据线条渐变计算仿射投影矩阵。

【讨论】:

  • 感谢您的回答。我正在对所有图像进行二值化,所以是的,背景会是这样的。我怎样才能适应线条?
【解决方案4】:

如果您使用某种机器学习工具箱进行文本识别,请尝试从所有车牌中学习 - 不仅仅是对齐的车牌。变换车牌或不变换车牌,识别结果应该一样好,因为通过变换,根据真实数字的新信息不会增强图像。

【讨论】:

    猜你喜欢
    • 2012-11-23
    • 2016-10-27
    • 2012-07-06
    • 1970-01-01
    • 1970-01-01
    • 2019-02-27
    • 1970-01-01
    • 2013-03-26
    相关资源
    最近更新 更多