Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

openCV vs GIMP, edge detection fails in 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: Source image The output by openCV is openCV output The output by GIMP is GIMP output

Why such a big difference between the outputs by openCV and GIMP. The quality of output by GIMP surpasses openCV by light years.

like image 729
Xolve Avatar asked Jun 03 '11 11:06

Xolve


1 Answers

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 with 1, 0 as parameters and 0, 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.

like image 113
etarion Avatar answered Nov 02 '22 04:11

etarion