THE CANNY EDGE DETECTOR / the optimal edge pipeline

Four stages that turn a noisy raster into a clean line drawing: Gaussian blur quiets the noise, a Sobel gradient measures the slope, non-maximum suppression thins each ridge to a single pixel along its own normal, and hysteresis thresholds with memory — a strong edge, plus any weak pixel that can walk to a strong one. Canny derived the operator from an explicit uncertainty principle between detection and localization. Rendered, not quoted.

source Canny, J. — A Computational Approach to Edge Detection, IEEE Trans. PAMI PAMI-8(6):679–698, 1986. doi:10.1109/TPAMI.1986.4767851

Blue Team · builds & defends

3 THE MODEL

An edge is a step in intensity. The pipeline is four exact operators, in order:

1. Blur — convolve with a separable Gaussian (integer kernels [1,2,1]/4 or [1,4,6,4,1]/16). Sets the scale.

2. Gradient — Sobel Gx,Gy; magnitude √(Gx²+Gy²), direction atan2(Gy,Gx).

3. Thin (NMS) — keep a pixel only if its magnitude is a local maximum along the gradient normal (direction quantized to 0/45/90/135°). A thick ridge collapses to width 1.

4. Hysteresis — two thresholds. Above HIGH = edge. Below LOW = discarded. Between = edge only if connected (8-neighbour) to a strong edge.

5 THE LINEAGE

Stage 2 is borrowed: the-sobel-operator supplies the gradient field. Canny’s contribution is what comes after — thin that gradient to one pixel, then threshold it with memory.

Sobel answers “how steep, which way.” Canny answers “which of those responses is the edge, and which is just the ridge’s shoulder.” The classic pipeline is the pair, in series.

7 THE WITNESS

Re-measures the live pipeline on the constructed step image and reports the edge width. Truth is 1. If window 6 removes the thinning stage, the width jumps and this badge flips red — live.

witness idle
The Machine

4 DATA IN in ↓

A constructed 13×5 raster: a smoothed vertical intensity step (dark left → bright right). One true edge, whose gradient ridge is deliberately several pixels wide.

0 THE PANEL LIT

Live: blur → Sobel → NMS → hysteresis. Every strip is computed, not drawn.

0 mid max final edge
booting…

8 DATA OUT out ↓

A single-pixel-wide edge at the true step (column 5). Proven exact at boot: convolution = 8, edge width = 1, hysteresis’ three cases, heavier blur erases the fine line.

Red Team · attacks & breaks

1 THE ADVERSARY WALL

Detection vs. localization is a hard trade. Canny proved it: the same Gaussian that suppresses noise also displaces and erases genuine fine structure. There is no σ that is right everywhere — a corner, a texture edge, and a shadow boundary want different scales.

Hysteresis streaks and breaks. A noisy edge dipping below LOW splits into gaps; a bright background that grazes LOW near a strong edge floods in as false edge.

4-bin direction is coarse. Quantizing the normal to 0/45/90/135° mislocates diagonal ridges by up to half a pixel.

2 THE GRAVEYARD

“Canny finds every true edge.”
→ It is optimal for a step edge in Gaussian noise. It rounds corners, fragments junctions, and misses edges softer than its scale.

“It is parameter-free.”
→ σ, HIGH and LOW must be tuned; results move with all three. amber the ratio HIGH:LOW≈2:1 or 3:1 is a rule of thumb, not a theorem.

“NMS gives exact geometry.”
→ Thinning is exact only up to the direction quantization; sub-pixel edge location needs interpolation Canny does not specify.

6 THE TAMPER

The disclosed planted void: delete stage 3. Threshold the raw gradient with no thinning — the whole ridge (columns 3–8) survives as a thick multi-pixel band. The WITNESS in window 7 catches the width jump immediately.

Buttons live in window 0. selfcheck() also plants and heals this void internally at boot.