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

查看:2366
本文介绍了如何对齐图像 - 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.

编辑:我尝试了一种方法,该方法适用于所有类型的平板和各种角度。这样做与霍夫变换,但我没有成功。任何人都可以帮助我做这个?

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

任何帮助将非常感激。

推荐答案

解决方案首先在评论中由 @AruniRC 提示,然后由@belisarius 。以下是我在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方法检测边缘,使用Hough变换找到突出线,计算线角度,剪切变换以对齐图像。

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('\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)



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

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