读者注意:这是一个后续问题,请参考以下内容:
如何在MATLAB中选择Hough变换的最大强度?
计算在MATLAB中移动的位移
这个过程类似于我之前展示的过程。下面我使用你上一个问题的图像(因为你只提供了一个,我通过将第一个旋转10度来创建另一个)。
我们首先检测两个图像的线条。我们在Hough变换函数的帮助下完成这项工作。这看起来像应用于两个图像:
接下来,我们想要使用线端点作为控制点来执行图像配准。首先,我们确保两个图像中的点彼此对应。我这样做是通过使用convhull计算凸包,它自动按逆时针顺序对它们进行排序(或者它是在相反的方向!)。上面显示的数字表示订单。
最后,我们使用函数cp2tform来获得变换矩阵,我们使用它来对齐图像并提取平移,旋转和缩放。
以下是完整的代码:
%% # Step 1: read and prepare images
%# (since you provided only one, I created the other by rotating the first).
I1 = imread('http://i.stack.imgur.com/Se6zX.jpg');
I1 = rgb2gray( imcrop(I1, [85 35 445 345]) ); %# Get rid of white border
I2 = imrotate(I1, -10, 'bilinear', 'crop'); %# Create 2nd by rotating 10 degrees
%% # Step 2: detect the cross sign endpoints (sor