Question

I understand that you filter each pixel by a horizontal and vertical matrix that gives a horizontal and vertical gradient. The gradients represent the difference in color along their respective axis. That I understand. What I don't understand is how our final value is computed by squaring the gradients, adding them together, and then taking the square root of that. It must make sense somehow but I don't quite get it.

enter image description here

Was it helpful?

Solution

Together, the X and Y gradients make up a 2D vector, (G_x,G_y). You can think of this vector as an arrow based at the origin, which indicates the direction and the magnitude of the derivative of the image value at that point. (More accurately, the Sobol filter uses the local pixel values to compute a finite-difference approximation of a derivative).

Vectors have both a direction and a magnitude; if you are only interested in the magnitude of this vector, you need to compute its length. The Pythagorean theorem is how you compute this length: G = sqrt(G_x^2 + G_y^2).


The reason you want to use the vector length is that it is smoothly independent of the orientation of the edge.

If you try averaging or otherwise adding the absolute differences instead, your edge detector will be more sensitive to diagonal edges than to vertical or horizontal ones; alternatively, if you try taking the largest absolute value of the two vector elements, the reverse will be true. Also, neither alternative is a smooth function of the input vector, which will cause "kinks" at vector orientations for which the functions aren't smooth.

If you are writing your own filter, it is easy to try this out. A lack of smoothness and orientation-independence will show up as ugly artifacts in the result of your edge-detection filter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top