该解决方案首先在
@AruniRC的评论中被暗示,然后在
@belisarius在数学中实现.以下是我在MATLAB中的解释.
想法基本相同:使用Canny方法检测边缘,使用霍夫变换找到突出线,计算线角度,最后执行剪切变换以对齐图像.
%# 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 a