如何对齐图像 - Matlab [英] How to align image - Matlab

查看:77
本文介绍了如何对齐图像 - Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to know how to align an image in Matlab for further work.

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

for example I have the next license plate image and I want to recognize all the digits.

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

my program works for straight images so, I need to align the image and then preform the optical recognition system.

该方法应尽可能适用于各种板材和各种角度.

The method should be as much as universal that fits for all kinds of plates and in all kinds of angles.

我尝试使用 Hough Transform 来做到这一点,但我没有成功.有人可以帮我做这件事吗?

I tried to do this with Hough Transform but I didn't Succeed. anybody can help me do to this?

将不胜感激任何帮助.

推荐答案

该解决方案首先由 @AruniRC 暗示在评论中,然后由 @belisarius 在 Mathematica 中实现.以下是我在MATLAB中的解读.

The solution was first hinted at by @AruniRC in the comments, then implemented by @belisarius in Mathematica. The following is my interpretation in MATLAB.

思路基本相同:用Canny方法检测边缘,用霍夫变换找到突出的线条,计算线条角度,最后执行剪切变换以对齐图像.

The idea is basically the same: detect edges using Canny method, find prominent lines using Hough Transform, compute line angles, finally perform a Shearing Transform to align the image.

%# 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('	heta (degrees)'), ylabel('
ho'), 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)

这篇关于如何对齐图像 - Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆