Lulumoy Studio

Math guide

Canny edges

Canny edge detector: finds the lines of maximum gradient and decides which are edges with two thresholds. The result is a binary (0 or 255) grayscale image.

Gx=Sx∗I,Gy=Sy∗I,|∇I|=|Gx|+|Gy|,θ=atan2(Gy,Gx)
Sx, Sy are the Sobel operators of the chosen size. OpenCV uses the L1 norm of the gradient by default.

Non-maximum suppression: a pixel remains a candidate only if its |∇I| is a maximum along direction θ, which thins edges to one pixel.

borde / edge / bordo⟺{|∇I|>T2T1<|∇I|≤T2y conectado a un borde fuerte / and connected to a strong edge / e connesso a un bordo forte
Hysteresis: pixels below T1 are discarded.

Parameters

ParameterMeaning
Lower thresholdT1, low threshold.
Upper thresholdT2, high threshold. A ratio T2/T1 between 2 and 3 usually works well.
Sobel apertureSize of the Sobel operator (3, 5 or 7). Larger apertures give larger gradients, so thresholds must rise accordingly.

References

  1. OpenCV 4.x documentation — Feature Detection (Canny). docs.opencv.org/4.x/dd/d1a/group__imgproc__feature.html
  2. J. Canny. "A computational approach to edge detection." IEEE Transactions on Pattern Analysis and Machine Intelligence, PAMI-8(6):679–698, 1986.