Sobel vs Canny Edge Detector

Push a test image through the full edge-detection pipeline behind robot vision — grayscale, Gaussian blur, Sobel gradients, non-max suppression, Canny hysteresis — and hover any step to inspect the math behind a single pixel.

Loading interactive simulation...

why blur first, and why two thresholds 🖖

A derivative amplifies whatever it's given, noise included — differentiate a raw image and every single-pixel fluctuation looks like an edge. Convolving with a Gaussian first (step 2) averages that noise away while barely touching the large-scale intensity changes that are real edges, which is why every practical gradient-based detector smooths before it differentiates. The Sobel kernels themselves are separable approximations of the partial derivatives ∂I/∂x and ∂I/∂y, weighted 1-2-1 across the perpendicular axis to bias the estimate toward the center row or column. A single threshold on the resulting magnitude forces an impossible choice: set it low and noise speckles the output, set it high and low-contrast edges break into dashed fragments. Hysteresis (step 6) escapes that trade-off by using two thresholds instead of one — the high threshold (T_high) finds edges it's confident about, and the low threshold (T_low), applied only to pixels already touching a strong edge, lets a real contour continue through a temporarily faint stretch without letting noise start a contour of its own. This is the same double-threshold idea used in flood-fill segmentation and in schmitt-trigger circuits, wherever a single cutoff would flicker.

Two questions about one image 🖖

Sobel and Canny ask different questions about the same picture. Sobel produces a gradient map: every pixel gets a number for how sharply brightness changes there, so boundaries come out thick and grayscale, like a soft glow. Canny takes that same gradient and forces a decision — non-maximum suppression keeps only the single brightest pixel across each ridge, thinning the glow to a crisp one-pixel line, then labels it edge or not. Toggle the Gradient and Canny tabs to watch a fuzzy map collapse into a clean outline.

Canny's edges hide a built-in trade-off 🖖

John Canny didn't tinker his way to a recipe. In his 1986 paper he framed edge detection as an optimization with three goals — detect real edges, locate them accurately, and respond only once per edge — and solved it with the calculus of variations; the answer came out almost exactly as the first derivative of a Gaussian. The catch he also proved: detection and localization pull against each other as the blur widens, so a bigger σ finds fainter edges but smears their position, and no single σ wins at both. Slide σ and watch it happen.

Example problems

  • Clean shapes - Geometric shapes — default Canny settings, clean binary edge map
  • Checkerboard gradient - Checkerboard — ideal step edges, maximum Sobel response at transitions
  • Circuit traces - Circuit board — low s preserves thin copper traces in Canny output
  • Smoothed face - Face with s=2.5 — heavy blur removes texture, keeping structural edges