openCV 与 GIMP,openCV 中边缘检测失败
我正在 openCV 中使用以下参数进行 Sobel 边缘检测:
cv.Sobel(mat, edgemat, 1, 1)
# mat -> source image
# edgemat -> taget output image
# 1 -> xorder (int) – Order of the derivative x
# 1 -> yorder (int) – Order of the derivative y
# apertureSize (int) – Size of the extended Sobel kernel -> its by default set to 3
我还使用 GIMP 对图像进行了 Sobel 边缘检测。
源图像为: openCV 的输出为 GIMP 的输出是
为什么 openCV 和 GIMP 的输出之间有这么大的差异。 GIMP 的输出质量比 openCV 好几个光年。
I am doing Sobel edge detection in openCV using the with following parameters:
cv.Sobel(mat, edgemat, 1, 1)
# mat -> source image
# edgemat -> taget output image
# 1 -> xorder (int) – Order of the derivative x
# 1 -> yorder (int) – Order of the derivative y
# apertureSize (int) – Size of the extended Sobel kernel -> its by default set to 3
I also did the Sobel edge detection on the image using GIMP.
The source image is:
The output by openCV is
The output by GIMP is
Why such a big difference between the outputs by openCV and GIMP. The quality of output by GIMP surpasses openCV by light years.
简单的回答:你做错了。请参阅文档 - 您正在做的是计算图像的 d^2/(dx dy) 导数 - 这意味着“水平边缘如何垂直变化”(或者等效地,“垂直边缘如何水平变化”),这意味着,对于一个垂直或水平边缘,您期望输出为零(因为它在垂直于它的方向上不会改变)。所以,你用 opencv 线所做的根本不是边缘检测。您可能想要像 sobel 这样的东西,以
1, 0
作为参数,以0, 1
为参数,然后对这些结果求平方并将它们相加,然后取结果的平方根。这可能会导致类似 GIMP 正在做的事情。Simple answer: You are doing it wrong. See the documentation - what you are doing is computing the
d^2/(dx dy)
derivative of the image - that means "how do the horizontal edges change vertically" (or, equivalently, "how do the vertical edges change horizontally"), that means, for a vertical or horizontal edge you expect an output of zero (because it doesn't change in the direction perpendicular to it). So, what you are doing with your opencv line is not edge detection at all. You probably want something like sobel with1, 0
as parameters and0, 1
, then square those results and add them up, then take the square root of the result. That might result in something like what GIMP is doing.