Skip to main content
Back to the graphics atlas
FoundationsSegmentation & edges Algorithm Advanced

Canny Edge Detection

Build a cleaner final edge map by chaining smoothing, gradients, non-maximum suppression, and hysteresis thresholding.

Segmentation & edges is nested under Foundations , so the broader pipeline usually still applies here.

graphicsimage-processingedgespipeline

Interactive playground

Tweak the operator or scene live so the article connects to an immediate visual result.

Canny edge detection

Build a more selective edge map by smoothing, taking gradients, suppressing non-maxima, and linking weak edges to strong ones.

Input image

Dual-threshold edge map

96 × 96 live preview

Raise the high threshold for stricter edges, or widen the gap to see hysteresis decide what survives.

Family

Foundations -> Segmentation & edges

Turn raw pixels into masks, boundaries, and simpler structural signals.

Builds on

3 topics

Read these first if you want the surrounding pipeline context.

Unlocks

1 next topic

Use these follow-ups when you want to keep turning the image-processing pipeline forward.

Learning paths

1

This topic appears in curated graphics progressions so the next step is obvious.

Choose this over that

Choose Canny when the edge map itself matters

Canny is a pipeline, not just a kernel, so it is heavier but more deliberate than Sobel or Laplacian-style responses.

Current topic

Canny Edge Detection

Choose this when: You need non-maximum suppression, hysteresis, and a cleaner final contour set.

Choose something else when: A quick gradient visualization or cheaper edge hint is enough.

Segmentation & edges Open topic

Sobel Edge Detection

Choose this when: The goal is a direct gradient map, not a fully curated edge detector.

Choose something else when: Thin final contours matter more than raw gradient strength.

Segmentation & edges Open topic

Laplacian and Laplacian of Gaussian

Choose this when: Second-derivative behavior or zero crossings are the main signal of interest.

Choose something else when: You want a more standard contour extraction pipeline.

Problem

A raw edge response is usually too thick, too noisy, and too ambiguous to serve as a final contour map. You need a full pipeline that turns edge evidence into stable, thin boundaries.

Intuition

Canny is not one kernel. It is a sequence: denoise first, compute gradients, suppress non-maxima so only local ridge peaks remain, then keep weak edges only when they connect to strong ones.

Core idea

  • Smooth the image, often with a Gaussian blur.
  • Compute gradient magnitude and direction, typically with Sobel-like kernels.
  • Apply non-maximum suppression so wide gradient ridges become thin candidates.
  • Use a high and low threshold with hysteresis so weak edges survive only when attached to strong ones.

Worked example

A textured but noisy boundary may produce many small gradient responses. Non-maximum suppression thins the ridge, and hysteresis prevents isolated weak specks from surviving while preserving a longer connected contour.

Complexity

Each stage is linear in the number of pixels, so the full pipeline stays O(WH) with a moderate constant factor from the multiple passes.

When to choose it

  • Choose it when the edge map itself is the final product or an important intermediate artifact.
  • Choose Sobel when you only need a quick gradient magnitude visualization.
  • Choose thresholding when you want region membership rather than contour extraction.

Key takeaways

  • Canny is a multi-stage detector, not a single stencil.
  • Non-maximum suppression and hysteresis are what make it cleaner than a raw gradient map.
  • It is a strong default when final contour quality matters.
  • Its prerequisites explain its structure: blur, gradients, and threshold logic all appear inside it.

Practice ideas

  • Compare Sobel and Canny on the same noisy image and inspect contour thickness.
  • Vary the high and low thresholds and observe when edges fragment or over-connect.
  • Feed a Canny result into connected-components labeling to count contour fragments.

Relation to other topics

  • Gaussian blur and Sobel appear as building blocks inside Canny.
  • Thresholding contributes the high/low edge decision logic, but in a connected hysteresis form rather than a one-shot mask split.
  • Connected-components labeling becomes useful after Canny when you want region or contour-level analysis.

Build on these first

These topics supply the mental model or preceding stage that this page assumes.

What this enables

Once the current operator feels natural, these are the most useful follow-up jumps.

Related directions

These topics live nearby conceptually, even if they are not strict prerequisites.

More from Segmentation & edges

Stay in the same family when you want parallel operators built from the same mental model.

Paths that include this topic

Follow one of these sequences if you want a guided next step instead of open-ended browsing.

From the blog

Pair the graphics atlas with recent writing from the broader site whenever you want a wider engineering lens.