Chapter 08 · Segmentation & Description

Edge Detection

The first real decision about what's "in" an image rather than just how it looks — and the direct ancestor of every keypoint detector in Chapter 11.

8.1 Edges as derivatives

IN SHORT

An edge is just a spot where brightness changes fast. "How fast is it changing, and in which direction" is literally a derivative — the same math as "how steep is this hill, and which way is downhill" applied to brightness instead of elevation.

An edge is, definitionally, a place where intensity changes rapidly over a short spatial distance. The first derivative of intensity is large in magnitude at an edge and near zero in flat regions; the second derivative crosses zero exactly at the edge center. Both facts are used, by different detectors, to localize edges.

first derivative:  |∇f| = √( (∂f/∂x)² + (∂f/∂y)² )      direction:  θ = atan2(∂f/∂y, ∂f/∂x)
Plain-language version

Literally picture a hillside — but the "height" at every point is the image's brightness instead of elevation. A flat, uniform region of the image is like flat ground: no slope, gradient near zero. A sharp edge — like the boundary between a dark shadow and bright sunlit ground — is like a cliff: extremely steep, large gradient magnitude. The gradient direction is simply "which way is uphill" — pointing from dark toward light, always perpendicular to the edge itself, the same way the steepest path up a real cliff runs perpendicular to the cliff's edge, not along it.

Demo — Gradient Magnitude & Direction hover to inspect direction at a point
Right: gradient magnitude (Sobel). Hover to see the gradient direction at that point — always perpendicular to the local edge, pointing from dark toward light. This direction field is exactly what SIFT/HOG-style descriptors (Chapter 11) accumulate into orientation histograms.

8.2 The Canny edge detector

IN SHORT

Canny is a 4-step recipe that turns a messy, noisy gradient map into a clean, thin, connected line drawing of an image's edges — like tracing over a blurry photo with a pen, but automated and precise.

Canny is less "one filter" and more a small, deliberate pipeline, still the reference standard for binary edge maps because each stage fixes a specific failure mode of naive gradient thresholding:

  1. Gaussian smoothing — suppress noise before differentiating (recall Chapter 5: differentiation amplifies noise, so filter first).
  2. Gradient computation — Sobel (or similar) magnitude and direction at every pixel.
  3. Non-maximum suppression — thin wide gradient ridges down to a single-pixel line, by keeping a pixel only if it's a local maximum along the gradient direction.
  4. Hysteresis thresholding — two thresholds instead of one: pixels above the high threshold are definite edges; pixels above the low threshold are kept only if connected to a definite edge. This lets a strong, continuous edge "pull along" a weaker, noisier stretch of itself rather than breaking into dashes.
Everyday analogy for hysteresis thresholding

Think of it like judging a rumor's credibility. A claim backed by strong, direct evidence (above the high threshold) is accepted outright. A weak, unconfirmed claim (below the low threshold) is rejected outright. But a shaky claim that's directly connected to — corroborated by — something already accepted gets pulled in too. This is exactly why hysteresis produces continuous, unbroken edge lines instead of a dashed, spotty mess: a faint stretch of a real edge gets "vouched for" by the strong, confident stretch right next to it.

Demo — Canny Pipeline, Stage by Stage step through the stages

8.3 The Laplacian of Gaussian and zero-crossings

IN SHORT

A different edge-finding trick: instead of looking for the steepest slope, look for where the slope stops increasing and starts decreasing — the "crest" of the change, found where a second derivative flips from positive to negative.

An alternative philosophy: smooth with a Gaussian, then take the second derivative (Laplacian). Edges appear as zero-crossings in the result — points where the value flips sign — rather than as local maxima in a gradient magnitude map. This combined operator, the Laplacian of Gaussian (LoG), is often approximated by a Difference of Gaussians (DoG) for speed: subtract two differently-blurred versions of the same image. The DoG approximation reappears directly in Chapter 11 — it's the core detection signal inside SIFT's scale-space keypoint search.

8.4 Why edge detection alone isn't feature matching

IN SHORT

Knowing "there's an edge here" doesn't tell you which edge it is. Every stretch of a fence-line looks the same as every other stretch — you need something more distinctive than "edge/not edge" to actually match one specific point in one image to the same point in another.

An edge map tells you where structure exists but not what makes one edge distinguishable from another edge nearby — every edge pixel looks locally similar to every other edge pixel. Matching two images by their edge maps alone is therefore usually a losing strategy for anything beyond gross alignment; you need a description that's distinctive at a point, not just a binary "edge / not edge" label at every pixel. That distinctiveness requirement is exactly what motivates going from edges to corners and keypoints in the next chapter's project track.

Why ORB/Harris matching often looks scattered across modalities

ORB and Harris matching between a DEM and an orthoimage often produces scattered, inconsistent match lines — visually, exactly the failure mode you'd expect from detectors that are still fundamentally edge/corner-strength based, applied to two images whose edges exist for different physical reasons (elevation discontinuities vs. reflectance discontinuities). The gradient direction and magnitude at a "true" matching crater rim may agree well; the intensity values surrounding it almost certainly won't, which is exactly what a purely intensity-based descriptor is vulnerable to.