为什么OpenCV中的结构元素不对称? [英] Why is the structuring element asymmetric in OpenCV?

查看:191
本文介绍了为什么OpenCV中的结构元素不对称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么OpenCV中的结构元素不对称?

Why is the structuring element asymmetric in OpenCV?

cv2.getStructuringElement(cv2.MORPH_ELLIPSE, ksize=(4,4))

返回

array([[0, 0, 1, 0],
       [1, 1, 1, 1],
       [1, 1, 1, 1],
       [1, 1, 1, 1]], dtype=uint8)

为什么不是

array([[0, 1, 1, 0],
       [1, 1, 1, 1],
       [1, 1, 1, 1],
       [0, 1, 1, 0]], dtype=uint8)

相反?

奇数大小的结构元素也相对于90度旋转不对称:

Odd-sized structuring elements are also asymmetric with respect to 90-degree rotations:

array([[0, 0, 1, 0, 0],
       [1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1],
       [0, 0, 1, 0, 0]], dtype=uint8)

这是什么目的?

推荐答案

除了它是这种形状的许多可能插值之一之外,没有其他目的.对于大小为5的椭圆,如果已满,它将与MORPH_RECT相同,并且如果从侧面除去与顶部相同的两个,则将是菱形.无论哪种方式,它的实际实现方式在源代码中在源代码中是您所期望的-它通过distance函数创建一个圆,并使用接近整数的整数来获取二进制像素.在该文件中搜索cv::getStructuringElement,您会找到实现,这太花哨了.

There's no purpose for it other than it's one of many possible interpolations for such a shape. In the case of the ellipse with size 5, if it were full it would just be the same as the MORPH_RECT and if the same two were removed from the sides as from the top it would be a diamond. Either way, the way it's actually implemented in the source code is what you would expect---it creates a circle via the distance function and takes near integers to get the binary pixels. Search that file for cv::getStructuringElement and you'll find the implementation, it's nothing too fancy.

如果您认为应该对此功能进行更新,请在GitHub上打开具有已实现版本的PR,或者首先讨论此问题.我认为在这里成功的贡献很容易,而且我敢说对称性很强.人们会期望使用椭圆形内核处理对称图像的结果将不依赖于图像的方向.

If you think an update to this function should be made, then open up a PR on GitHub with the implemented version, or an issue to discuss it first. I think a successful contribution would be easy here and I'd venture that the case for symmetry is strong. One would expect the result of a symmetric image being processed with an elliptical kernel wouldn't depend on orientation of the image.

这篇关于为什么OpenCV中的结构元素不对称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆