MATLAB 中的粗糙线
使用 霍夫线 检测图像中的线条后,如何使用它来计算变化参考图像的线条角度(旋转)?
After detecting the lines in an image using Hough lines, how can I use it to calculate the change in angle (rotation) of the lines of a reference image?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
读者注意事项:这是一个后续问题,请参阅以下内容了解背景:
该过程与我之前展示的类似。下面我使用您上一个问题中的图像(因为你只提供了一个,我通过将第一个旋转 10 度创建了另一个)。
我们首先检测两个图像的线条。我们在 Hough 变换 函数。这看起来就像应用于两个图像:
接下来,我们要使用执行图像配准线端点作为控制点。首先,我们确保两个图像中的点彼此对应。我通过使用
convhull
会自动按逆时针顺序对它们进行排序(或者是相反的方向!)。上面显示的数字表示顺序。
最后,我们使用函数
cp2tform
< /a> 获取变换矩阵,我们用它来对齐图像并提取平移、旋转和缩放。以下是完整的代码:
这是提取线条端点的函数:
结果:
旋转恢复为几乎 10 度(有一些不可避免的误差),并且缩放实际上为 1(意味着没有缩放)。请注意,上面的示例中有一个平移组件,因为没有围绕十字标志的中心执行旋转。
Note to readers: This is a follow-up question, refer to these for background:
The process is similar to what I showed before. Below I am using the images from your previous question (since you provided only one, I created the other by rotating the first by 10 degrees).
We start by detecting the lines for the two images. We do this with the help of the Hough transform functions. This what it looks like applied to both images:
Next, we want to perform image registration using the line endpoints as control-points. First, we make sure the points correspond to each other in the two images. I do this by computing the convex hull using
convhull
which automatically sorts them in counterclockwise-order (or is it in the opposite direction!). The numbers shown above indicate the order.Finally, we use the function
cp2tform
to get the transformation matrix, which we use to align the images and extract the translation, rotation, and scaling.The following is the complete code:
And here's the function that extract the lines endpoints:
with the result:
The rotation is recovered as almost 10 degrees (with some inevitable error), and scaling is effectively 1 (meaning there was no zooming). Note that there was a translation component in the above example, because rotation was not performed around the center of the cross sign).
我不确定霍夫变换的 MATLAB 实现是什么,但线的方向将简单地与您最初用来识别直线的角度成直角(90 度或 pi/2 弧度)。
我希望这有帮助。网络上有关于霍夫变换的大量报道,维基百科是一个很好的起点。
I am not sure what the MATLAB implementation of the Hough transform is, but the orientation of the line will be simply be at a right angle (90 degrees or pi/2 radians) to the angle you've used to identify the line in the first place.
I hope that helps. There's decent coverage of Hough transforms on the web and Wikipedia is a good place to start.