The Canny edge detector smooths the image, finds strong local changes, thins the responses, and keeps reliable weak responses that connect to strong edges.

Main idea

Canny uses a different stage for each main problem: smoothing for noise, non-maximum suppression for thickness, and hysteresis for varying edge strength.


Complete Pipeline

flowchart LR

I["Input image"] --> G["Gaussian derivative<br/>magnitude and direction"]
G --> N["Non-maximum suppression<br/>thin responses"]
N --> H["Hysteresis thresholding<br/>link reliable weak edges"]
H --> O["Edge map"]

Step 1: Gaussian Derivative Filtering

The Gaussian derivatives smooth and differentiate in one operation:

Here, is a positive, unnormalised Gaussian. This sign convention differs from the inverted Gaussian convention in Laplacian of Gaussian (LoG).

Apply the two filters to the image:

Then calculate the magnitude and direction described in Image Gradient and Edge Detection:


Step 2: Non-Maximum Suppression

The gradient response can form a thick ridge around one boundary. Non-maximum suppression keeps only the ridge maximum:

  1. Use to identify the gradient direction
  2. Compare the centre magnitude with the two neighbouring magnitudes along that direction
  3. Keep the centre only when it is the largest value
  4. Suppress the other responses to zero

Why compare along the gradient direction?

The gradient direction crosses the intensity boundary. The largest value along this direction is the centre of the edge response.

The output is a thin set of candidate edge pixels.


Step 3: Hysteresis Thresholding

Hysteresis uses a low threshold and a high threshold , where .

Magnitude ClassificationDecision
Strong edgeAlways keep
Weak edgeKeep only when connected to a strong edge
Non-edgeDiscard

For example, if and :

  • is a strong edge and stays
  • stays only when it connects to a strong edge
  • is discarded

Weak does not mean false

A weak response can be part of a real boundary. Connectivity to a strong edge supplies the supporting evidence.


Parameter Trade-offs

Parameter changeBenefitRisk
Decrease Retains fine detailRetains more noise
Increase Produces smoother responsesCan remove fine boundaries
Lower and Keeps more weak edgesKeeps more false edges
Raise and Removes more false edgesCan remove true weak boundaries

The required balance depends on whether complete boundaries or a clean edge map is more important.


What Each Stage Fixes

Raw-edge problemCanny stage
Noise sensitivityGaussian derivative filtering
Thick responsesNon-maximum suppression
Weak responses connected to strong edgesHysteresis thresholding

The output remains a set of local and connected edge pixels. The Hough Transform can use these pixels to detect a global line.