Chapter 31: Edge Detection and Gradients
Capturing abrupt intensity changes with gradients (Sobel) and the Laplacian. Canny, which yields thin, connected contours via non-maximum suppression and hysteresis.
An edge is where intensity changes abruptly: the outline of an organ, the boundary between bone and soft tissue, the rim of a defect. Finding these underpins segmentation (Chapter 32), alignment, and feature extraction. The idea of edge detection comes down to differentiation. Where intensity changes abruptly, the first derivative (the gradient) is large and the second derivative (the Laplacian) crosses zero.
Edges seen in one dimension. Top: intensity f (a smooth step). Middle: first derivative f' (the gradient, peaking at the edge). Bottom: second derivative f'' (the Laplacian, crossing zero at the edge). An edge is a gradient peak, or a Laplacian zero crossing.
The figure above shows it in one dimension. The gradient of a smooth step peaks at the edge, and the Laplacian crosses zero at the edge. These are two views of an edge: a "gradient peak" or a "Laplacian zero crossing."
Sobel and the Laplacian
In two dimensions, the gradient is measured in both the horizontal and vertical directions. The Sobel filter approximates the horizontal gradient and vertical gradient with small kernels and takes the gradient magnitude as edge strength. The kernels build in a light smoothing, giving some robustness to noise. The Laplacian is the second derivative and crosses zero at an edge. Picking the zero-crossing locations gives edges, but the second derivative is sensitive to noise, so it is usually preceded by a Gaussian smoothing (LoG, Laplacian of Gaussian).
Thresholding the gradient or Laplacian gives an edge image, but done naively the edges come out thick, and noise turns into false edges.
Canny: thin, connected contours
The Canny method suppresses these weaknesses and produces thin, connected contours through these stages.
- Smoothing: reduce noise with a Gaussian.
- Gradient: compute gradient magnitude and direction with Sobel.
- Non-maximum suppression: remove pixels that are not a local maximum along the gradient direction, thinning thick ridges to one pixel wide.
- Double threshold: split into strong edges (above the high threshold) and weak edges (above the low threshold).
- Hysteresis: keep only the weak edges that connect to a strong edge.
Non-maximum suppression thins the contour, and hysteresis discards isolated weak edges from noise while linking the real contours. Together they give far cleaner edges than a simple threshold.
Simulation: comparing three methods
A phantom with a little noise is processed with Sobel (gradient magnitude), Laplacian (magnitude of the second derivative), and Canny. Moving the threshold changes how many edges are picked up. Sobel gives thicker contours, and lowering the threshold makes noise appear as false edges. Canny thins to one pixel with non-maximum suppression and yields a connected contour with noise suppressed by hysteresis. Watch the edge-pixel fraction (edge %) too.
Original (noisy)
Edge result
A phantom with a little noise is processed with Sobel (gradient magnitude), Laplacian (magnitude of the second derivative), and Canny. The threshold changes how many edges are picked up. Sobel gives thicker contours, and lowering the threshold turns noise into false edges. Canny thins to one pixel with non-maximum suppression and yields a connected contour with noise suppressed by hysteresis.
Key points
An edge is an abrupt intensity change, captured as a peak of the first derivative (gradient) or a zero crossing of the second derivative (Laplacian). Sobel gives gradient magnitude with kernels, and the Laplacian gives zero crossings, but differentiation is noise-sensitive and is combined with smoothing. Canny stacks smoothing, gradient, non-maximum suppression, double thresholding, and hysteresis to produce thin, connected contours. Edges are the entry point to segmentation and feature extraction.
References
- Canny J. A Computational Approach to Edge Detection. IEEE Transactions on Pattern Analysis and Machine Intelligence 8, 679–698 (1986).
- Marr D, Hildreth E. Theory of Edge Detection. Proceedings of the Royal Society B 207, 187–217 (1980) — LoG (zero crossings).
- Gonzalez RC, Woods RE. Digital Image Processing, 4th ed. Pearson (2018).
Chapter 30: Frequency-Domain Filtering
Weighting by frequency through the 2D Fourier transform. Low-pass, high-pass, and notch. Removing periodic noise.
Chapter 32: Segmentation
Extracting structures with thresholding (Otsu), region growing, morphology, and connected components. From classical methods to learned (U-Net).