我需要知道如何在Matlab中对齐图像以进行进一步的工作。
例如,我有下一个车牌图像,我想识别所有 数字。
我的程序适用于直接图像,所以我需要对齐图像然后 预先形成光学识别系统。
该方法应该适用于所有类型的板和各种角度的通用方法。
编辑:我试图用Hough Transform做到这一点,但我没有成功。有谁可以帮我做到这一点?
任何帮助将不胜感激。
答案 0 :(得分:15)
解决方案首先在评论中由@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)
答案 1 :(得分:6)
答案 2 :(得分:3)
如果您正在使用某种机器学习工具箱进行文本识别,请尝试从所有板块中学习 - 不仅仅是对齐的板块。如果你改变平板或不转换识别结果应该同样好,因为通过转换,根据真实数字的新信息不会增强图像。
答案 3 :(得分:0)
如果所有图像都具有类似的深色背景,则可以对图像进行二值化,使线条适合明亮区域的顶部或底部,并根据线条渐变计算仿射投影矩阵。