ScientiaLux
strataquest Glossary Canny Edge Detector
BOM Operation

Canny Edge Detector

Multi-stage edge detection producing thin, connected contours

View
Definition
A multi-stage edge detection algorithm that combines Gaussian smoothing, gradient computation, non-maximum suppression, and hysteresis thresholding to produce thin, connected edge contours — the gold standard for edge detection in image processing.
Six-Stage Pipeline
Smooth → gradient → direction → quantize → thin → threshold
Non-Maximum Suppression
Produces thin, single-pixel-wide edges
Hysteresis Thresholding
Two thresholds eliminate noise while preserving connectivity
Connected Contours
Produces closed, continuous boundary lines

How It Works

The Canny edge detector operates in six sequential stages:

  1. Gaussian smoothing — Convolve the image with a Gaussian kernel to suppress noise. The sigma parameter controls the scale of edges detected.
  2. Gradient magnitude — Apply Sobel operators to compute edge strength: E = |Gx| + |Gy| (fast L1 norm) or E = √(Gx² + Gy²) (accurate L2 norm).
  3. Gradient direction — Compute edge orientation: θ = arctan(Gy/Gx) at each pixel.
  4. Direction quantization — Snap continuous angles to four discrete directions: 0°, 45°, 90°, 135°. This defines the direction perpendicular to the edge.
  5. Non-maximum suppression — Compare each pixel's gradient magnitude to its two neighbors along the gradient direction. Only local maxima survive — all other pixels are set to zero. This thins thick edge responses to single-pixel-wide lines.
  6. Hysteresis thresholding — Apply two thresholds: T_high (strong edges, always kept) and T_low (weak edges). Starting from strong edge pixels, trace connected paths through weak edge pixels. Weak edges connected to strong edges are kept; isolated weak edges are discarded.
Simplified

The Canny detector finds edges in six steps: (1) smooth out noise, (2) find where intensity changes rapidly, (3) figure out which direction the edge runs, (4) thin edges to single-pixel lines by keeping only the strongest point perpendicular to each edge, and (5-6) use two thresholds to keep strong edges and weak edges that connect to them, discarding isolated noise.

Image Processing Foundation

The Canny edge detector implements John Canny's three optimality criteria for edge detection (1986):

Three Criteria

  1. Good detection — Low probability of missing real edges or detecting false edges. Achieved by Gaussian smoothing (reduces noise-induced false edges) and hysteresis thresholding (preserves weak-but-real edges).
  2. Good localization — Detected edges should be as close as possible to the true edge location. Achieved by non-maximum suppression, which places the edge at the exact gradient maximum.
  3. Single response — Only one response per edge. Achieved by non-maximum suppression, which eliminates multiple responses from thick edge regions.

Comparison with Other Detectors

Solomon & Breckon note that Roberts Cross is "fast but very sensitive to noise." Sobel/Prewitt produce thick edge responses that need post-processing. The Laplacian is "very sensitive to noise" and produces double edges at step transitions. The Canny detector addresses all these limitations systematically.

Parameter Sensitivity

The Gaussian sigma controls the scale of edges detected — large sigma detects only large-scale, prominent edges while suppressing fine detail. The ratio T_high/T_low is typically 2:1 or 3:1. Setting these parameters requires understanding the spatial scale and contrast of the structures of interest.

Simplified

The Canny detector was designed to meet three mathematical criteria: detect all real edges, place them precisely, and report each edge only once. Simpler methods fail at one or more of these — gradient thresholding produces thick edges, Laplacian is noise-sensitive, Roberts is too simple for real images. The Canny detector's multi-stage approach achieves all three goals simultaneously.

Parameters & Settings

ParameterTypeDescription
InputGrayscale imageThe image to detect edges in.
Gaussian SigmaFloatSmoothing parameter. Larger values detect coarser edges and suppress fine detail. Start at 1.0.
T_highNumericUpper hysteresis threshold. Gradient values above this are always classified as edges.
T_lowNumericLower hysteresis threshold. Gradient values between T_low and T_high are classified as edges only if connected to strong edges. Typical ratio: T_high/T_low = 2–3.
Simplified

Three settings: Sigma (smoothing — larger values detect only prominent edges), T_high (strong edge threshold), and T_low (weak edge threshold, typically T_high/2 or T_high/3). Start with sigma=1.0 and adjust thresholds based on edge contrast.

Connected Terms

Share This Term
Term Connections