CT Lab

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.

edgefintensityf'gradientf''Laplacianpeakzero crossing

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 ff' of a smooth step ff peaks at the edge, and the Laplacian ff'' 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 gxg_x and vertical gradient gyg_y with small 3×33\times3 kernels and takes the gradient magnitude gx2+gy2\sqrt{g_x^2 + g_y^2} 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.

  1. Smoothing: reduce noise with a Gaussian.
  2. Gradient: compute gradient magnitude and direction with Sobel.
  3. Non-maximum suppression: remove pixels that are not a local maximum along the gradient direction, thinning thick ridges to one pixel wide.
  4. Double threshold: split into strong edges (above the high threshold) and weak edges (above the low threshold).
  5. 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)

WL 0.500 / WW 1.00Drag to adjust WL/WW

Edge result

WL 0.500 / WW 1.00Drag to adjust WL/WW
Edge pixels2.4%

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 3×33\times3 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).

On this page