Skip to content
AI360Xpert
Beta

Canny Edge Detector Stages

Canny chains smoothing, gradients, thinning, and smart thresholding into thin clean edges. Weak pixels survive only beside strong ones.

Canny thins gradient ridges to one pixel, then keeps weak pixels only when they connect to strong ones.
Canny thins gradient ridges to one pixel, then keeps weak pixels only when they connect to strong ones.

Why Does This Exist?

Raw gradient maps are thick, broken, and threshold-fragile: one cutoff keeps noise and drops faint edges, another keeps faint edges and floods. Canny's 1986 pipeline fixes all three complaints in sequence. Gaussian smoothing hushes noise, Sobel gradients measure strength and direction, thinning narrows ridges to one pixel, and hysteresis thresholding links faint segments to strong ones instead of judging each pixel alone.

It remains the default classical detector inside spatial filtering. Use LoG zero-crossings when you need closed contours instead of linked chains.

Think of It Like This

Tracing a faint trail

Follow a hiking trail by painting only the clearest footprints, then filling gaps with fainter prints that continue the same line, while ignoring lone prints in the grass. Strong pixels are clear footprints, weak ones are faint but aligned, and isolated specks are animal tracks to discard. Hysteresis is that rule: faint evidence counts only when it extends something certain.

How It Actually Works

Four stages run in order. Smoothing blurs with a Gaussian at sigma you choose. Gradients come from Sobel GxG_x and GyG_y, giving magnitude and direction per pixel. Non-maximum suppression thins ridges: each pixel survives only if its magnitude beats both neighbours along the gradient direction, leaving one-pixel lines. Double thresholding then labels pixels above the high threshold as strong, below the low threshold as discarded, and between as weak. Hysteresis keeps weak pixels only when connected, directly or through other weak pixels, to a strong one.

Worked example

Thresholds low 50 and high 100 meet four pixels with magnitudes 120, 70, 75, and 30. The 120 is strong and kept. The 70 is weak but touches the strong pixel, so hysteresis keeps it as a continuing edge. The 75 is also weak but isolated, so it is discarded despite beating 70. The 30 falls below low and is discarded outright. Connectivity, not raw strength, decides the middle two.

Watch Out For

Thresholds tuned to one image

Thresholds that sing on one photo fail on the next because contrast and lighting shift gradient scales. The symptom is perfect edges on the demo image and emptiness or floods everywhere else. Set thresholds from the gradient histogram, such as a high percentile for the upper one, and re-tune per lighting condition rather than hard-coding.

Skipping sigma on noisy input

Running Canny with a tiny sigma on grainy images feeds speckle into every later stage, and no thresholding rescues the result. The symptom is hair-like false edges coating flat regions. Raise the Gaussian sigma until flat areas go quiet, accepting slightly rounded corners as the price.

The Quick Version

  • Canny chains smooth, gradient, thin, threshold, and link stages.
  • Non-maximum suppression narrows every ridge to a single pixel.
  • Double thresholds label strong, weak, and discarded pixels.
  • Hysteresis keeps weak pixels only when joined to strong chains.
  • Tune sigma and thresholds per lighting; no universal pair exists.