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:
- Use to identify the gradient direction
- Compare the centre magnitude with the two neighbouring magnitudes along that direction
- Keep the centre only when it is the largest value
- 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 | Classification | Decision |
|---|---|---|
| Strong edge | Always keep | |
| Weak edge | Keep only when connected to a strong edge | |
| Non-edge | Discard |
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 change | Benefit | Risk |
|---|---|---|
| Decrease | Retains fine detail | Retains more noise |
| Increase | Produces smoother responses | Can remove fine boundaries |
| Lower and | Keeps more weak edges | Keeps more false edges |
| Raise and | Removes more false edges | Can 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 problem | Canny stage |
|---|---|
| Noise sensitivity | Gaussian derivative filtering |
| Thick responses | Non-maximum suppression |
| Weak responses connected to strong edges | Hysteresis thresholding |
The output remains a set of local and connected edge pixels. The Hough Transform can use these pixels to detect a global line.