Skip to content
CoreSource checked

Canny Edge Detection

Finds thin edges by smoothing, measuring gradients, suppressing nonmaxima, and linking thresholds.

Quick Facts

Compact metadata for implementation and discovery.

Category
Image Processing
Difficulty
Intermediate
Family
Edge Detection
Tier
Core
Status
Verified
Review
Source Checked
Sources
2
Formulas
1
Relationships
7
Code example
Ready
Visualization
Ready
Aliases
Canny Edge Detector

Overview

Canny edge detection reduces noise with smoothing, computes gradient magnitude and direction, thins responses with non-maximum suppression, and uses hysteresis thresholds to keep connected strong edges.

Core Concepts

pixel operationgradient responsefilter kerneledge detectionpixel neighborhoodlocal operationimage transform

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(w h)

Average

O(w h)

Worst

O(w h)

Space

O(w h)

When to Use

  • Use when a clean, thin edge map is needed from grayscale intensity structure.
  • Use when threshold and smoothing parameters can be tuned for the image scale.

When Not to Use

  • Avoid when texture or noise dominates meaningful edges.
  • Avoid when downstream code needs learned semantic boundaries rather than intensity edges.

What It Does

  • Smooths the image before gradient measurement
  • Computes gradient magnitude and direction
  • Thins and links edge responses with hysteresis

Use Cases

  • Classical edge maps for vision pipelines
  • Shape extraction before contour analysis
  • Teaching multi-stage image-processing pipelines

Inputs

  • Grayscale image
  • Low and high thresholds

Outputs

  • Binary edge map

Key Formulas (1)

Gradient magnitude

magnitude = √gx2 + gy2
magnitude = sqrt(gx^2 + gy^2)

Measures edge strength before non-maximum suppression and thresholding.

Pseudocode

  1. 1.Smooth the grayscale image with a Gaussian filter
  2. 2.Compute gradient magnitude and direction
  3. 3.Apply non-maximum suppression along gradient directions
  4. 4.Mark strong and weak edge pixels with two thresholds
  5. 5.Keep weak edges connected to strong edges

Canonical Example

Input
a grayscale image with a dark square on a light background
Output
thin edge pixels around the square boundary
Explanation
The square boundary creates strong gradients that survive suppression and hysteresis.

Implementation Notes

  • Choose Gaussian sigma and thresholds together.
  • Test non-maximum suppression on simple diagonal and vertical edges.
  • Keep border handling consistent between smoothing and gradient stages.

Common Pitfalls

  • Too little smoothing creates noisy edges; too much smoothing erases fine detail.
  • Poor high and low thresholds either break edges apart or keep too much noise.
  • Incorrect gradient-direction quantization makes non-maximum suppression jagged.

Interactive Mechanism Walkthrough

Spatial Primitive & Sweep-Line Canvas

Show a photo becoming gradients, thinned edges, and final connected edges.

Canny Edge Detection mechanism walkthrough step 1 of 5
Step 1 of 5: Smooth the grayscale image with a Gaussian filter
canny-pipeline

Notes

Canny's quality depends heavily on sigma and hysteresis thresholds.

Sources (2)

What each reference supports for this entry.

Canny Edge Detection

Paper

Original Canny paper supporting smoothing, non-maximum suppression, and hysteresis thresholding.

Open source

Computer Vision: Algorithms and Applications

Book

Computer-vision textbook support for Canny Edge Detection's feature, matching, flow, or multiscale image-analysis workflow.

Open source

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Canny commonly smooths the image before computing gradients.

Conceptual neighborSobel Edge Detection

Both use image gradients, but Canny adds thinning and hysteresis linking.

Tags

Image ProcessingEdge DetectionFiltering