gpt4 book ai didi

matlab - 如何对齐图像 - Matlab

转载 作者:太空宇宙 更新时间:2023-11-03 19:13:25 24 4
gpt4 key购买 nike

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

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

enter image description here

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

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

编辑: 我尝试使用 Hough 变换来执行此操作,但没有成功。有人可以帮我做这个吗?

任何帮助将不胜感激。

最佳答案

解决方案首先由 @AruniRC 暗示在评论中,然后由 @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)

canny_edges hough_transform lines_overlayed_image_aligned

关于matlab - 如何对齐图像 - Matlab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5770818/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com