Sobel 边缘检测、边缘方向
我已经实现了 Sobel 边缘检测器,并对计算边缘方向有一些疑问。
在完成索贝尔核卷积后,我使用这个函数来计算边缘强度。
Gxy = sqrt( pow(Gx, 2) + pow(Gy,2) )
其中 Gx 是 X 方向 Sobel 核的卷积和,Gy 是 Y 方向 Sobel 核的卷积和。 (注意X和Y方向的sobel内核是不同的内核)
Y内核:
- 1 2 1
- 0 0 0
- -1 -2 -1
X内核:
- -1 0 1
- -2 0 2
- -1 0 1
当我尝试计算时边缘方向(theta 以度为单位),我使用以下规则:
- 如果 Gy == 0 且 Gx == 0,则 theta = 0
- 如果 Gy != 0 且 Gx == 0,则 theta = 90
- 否则,theta = (arctan( Gy / Gx ) * 180) / PI
我所有的文档都告诉我角度应该是 > 0且< 360 和我继续获得负价值取向的边缘。在计算 theta 或卷积时,我是否做错了什么?或者我应该将 360 或 180 添加到负 theta 值?
提前致谢,
I've implemented a Sobel Edge Detector and had some questions about computing edge orientations.
I'm using this function to compute edge intensities after having done the sobel kernel convolution.
Gxy = sqrt( pow(Gx, 2) + pow(Gy,2) )
Where Gx is sum of the convolution for the sobel kernel in the X direction and Gy is sum of the convolution for the sobel kernel in the Y direction. (note the sobel kernel in the X and Y direction are different kernels)
Y kernel:
- 1 2 1
- 0 0 0
- -1 -2 -1
X kernel:
- -1 0 1
- -2 0 2
- -1 0 1
when I try to compute the edge orientation (theta is in degrees), I'm using the following rules:
- if Gy == 0 and Gx == 0, then theta = 0
- if Gy != 0 and Gx == 0, then theta = 90
- otherwise, theta = (arctan( Gy / Gx ) * 180) / PI
all my documentation is telling me the angles should be > 0 and < 360 and I continue to get edges with negative value orientations. Is there something I'm doing incorrectly when computing theta or my convolution? Or should i just add 360 or 180 to negative theta values?
thanks in advance,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
很难准确回答你的问题,因为你没有具体提到如何计算 arctan 函数。
例如,如果您使用标准库的atan函数,则负数角度是可以预料的。
此外,您会注意到,具有单个参数的
atan
只能返回第一和第四象限中的值(因为,例如,tan 45 == tan 225
当使用度)。如果您确实想要四个象限之一的角度(您应该真正问问自己这对您的应用程序是否重要),那么请查看 atan2.
It's hard to answer your question precisely because you haven't mentioned exactly how you calculate the arctan function.
For example, if you're using the standard library's atan function, then negative angles are to be expected.
Furthermore, you'll notice that
atan
with a single argument can only ever return values in the first and fourth quadrants (because, for example,tan 45 == tan 225
when using degrees).If you really want an angle in one of the four quadrants (you should really ask yourself if this matters for your application), then have a look at atan2.
如果您使用 OpenCV、C++,您可以执行以下操作:
计算 x/y 轴的边缘梯度'
使用 OpenCV 的 cartToPolar
If you are using OpenCV, C++ you could do the following:
Calculate edge gradients in x/y axis'
Calculate the angle and magnitude using OpenCV's cartToPolar