Theory
An edge is a place where image intensity changes sharply, usually at the boundary of an object, a shadow or a texture. Mathematically, edges are where the gradient of the image is large. For an image f(x, y) the gradient is the vector of partial derivatives (Gx, Gy), with
- magnitude |G| = √(Gx² + Gy²)
- direction θ = atan2(Gy, Gx), perpendicular to the edge.
On a discrete image the derivatives are approximated by convolution with small kernels: each output pixel is the weighted sum of its neighbourhood.
First-derivative operators
Sobel weights the center row twice, which adds a little smoothing and makes it less sensitive to noise than Prewitt. Roberts uses a 2×2 diagonal difference: it is fast and sharp but very noise sensitive.
Second-derivative operators
The Laplacian ∇²f = ∂²f/∂x² + ∂²f/∂y² responds to edges with a zero crossing rather than a peak.
Because second derivatives amplify noise, the image is usually smoothed first with a Gaussian. Combining the two gives the Laplacian of Gaussian (LoG).
The Canny detector
John Canny (1986) designed an edge detector for good detection, good localization and a single response per edge. It runs in five stages:
- Smoothing with a Gaussian to suppress noise.
- Gradient magnitude and direction, typically with Sobel.
- Non-maximum suppression: keep a pixel only if it is the local maximum along the gradient direction, which thins edges to one pixel.
- Double threshold: pixels above the high threshold are strong edges, between low and high are weak, below low are discarded.
- Hysteresis: weak pixels survive only if they connect to a strong pixel.
Canny recommended a high to low threshold ratio between 2:1 and 3:1.
Workbench
Run each operator on the same image and compare their maps. Canny exposes all five intermediate stages.
Input
Input preview
Parameters
Readout
- n/a
- n/a
Export
Procedure
- Load the Shapes sample, which has edges at many angles, a smooth gradient and a curve.
- Compute Sobel Gx, Gy and the gradient magnitude. Explain why Gx highlights vertical edges.
- Repeat with Prewitt and Roberts and compare edge thickness and noise.
- Apply the Laplacian with and without Gaussian smoothing.
- Run Canny with low/high thresholds of 50/150, then 20/60 and 100/200. Step through each stage in the output strip.
- Load Street at dusk and your own photograph and repeat steps 2 to 5.
- Start the webcam and run Canny live; note the frame rate in the readout.
- Save a figure of each operator for the report.
Results and Discussion
To be completed
Add your figures and observations: which operator produced the cleanest edges, how noise affected each, how the Canny thresholds changed the result, and what non-maximum suppression and hysteresis contributed.
Conclusion
To be completed
Summarize the trade-offs between gradient, Laplacian and Canny edge detection in your own words.