Feature Detection
Source: CS1674 Ch.4 Feature Detection. Topics: edges (Sobel, Canny), line/circle fitting (least squares, Hough), RANSAC, local interest points, and the Harris corner detector.
1. Edge Detection
An edge is a place of rapid change in the image intensity function. Edges are caused by:
- Depth discontinuity (object boundary / occlusion)
- Surface color discontinuity
- Illumination discontinuity (shadow, lighting change)
- Surface normal discontinuity (fold, crease)
Edges look like "steep cliffs" in the intensity profile. They correspond to extrema of the first derivative (or zero-crossings of the second derivative).
1.1 Image derivatives
For a discrete image
- Option 1: reconstruct a continuous image
, then differentiate. - Option 2: take the discrete derivative directly (filter form above).
1.2 Gradient
The gradient points in the direction of most rapid intensity increase:
- Edge strength = gradient magnitude
. - Edge direction = perpendicular to
, given by .
1.3 Smooth first!
On a noisy image, the derivative is dominated by noise. Smooth before differentiating:
By associativity, we can convolve the derivative kernel with the smoothing kernel once (a "derivative of Gaussian" filter) and apply it directly — saving a pass.
1.4 Derivative of Gaussian (DoG)
1D Gaussian
The 2D DoG is separable:
1.5 The Sobel filter
A common discrete approximation of the derivative of Gaussian:
- The
normalization is omitted in the standard Sobel; it does not change edge detection (only the magnitude scale). - Interpretation: blur (1D Gaussian on rows/cols) × 1D central difference.
2. Canny Edge Detector (Canny 1986, TPAMI)
Still the most widely used edge detector 35+ years later. Four steps:
Step 1 — Filter with derivative of Gaussian
Compute
Step 2 — Non-maximum suppression (NMS)
Thin the edges: a pixel
Step 3 — Thresholding (double threshold)
With low threshold
→ strong edge → no edge → weak edge
Step 4 — Hysteresis linking
- Strong edges are definitely edges.
- A weak edge is kept only if it connects to a strong edge within a local neighborhood (typically 8-connected).
Parameters:
- Large
→ detects large-scale (coarse) edges. - Small
→ detects fine details (but more noise).
3. Line Fitting
3.1 Least squares line fit
Given points
Closed-form solution via the normal equations:
Problem: least squares is not robust to outliers — a single bad point can ruin the fit.
3.2 The Hough Transform (Duda & Hart 1976)
Idea — voting: let each feature vote for every model compatible with it; look for parameter bins that receive many consistent votes.
- A line
in image space = a point in Hough space. - A single image point
maps to the line in Hough space. - Two image points map to two Hough lines whose intersection is the
of the line through both.
Polar parameterization (avoids unbounded
- Each edge point adds a sinusoid in
space. - Algorithm:
- Initialize accumulator
. - For each edge point
with gradient orientation : ; . - Find local maxima
; the line is .
- Initialize accumulator
Pros / Cons:
| Pros | Cons |
|---|---|
| Points processed independently → robust to occlusion/gaps | Search time grows exponentially with #params (O( |
| Noise unlikely to vote consistently | Hard to choose bin size (quantization) |
| Detects multiple instances in one pass | Memory for high-dim accumulator |
3.3 Circle detection by Hough
Circle of radius
4. RANSAC — RANdom SAmple Consensus (Fischler & Bolles 1981)
Goal: fit a model in the presence of outliers by finding inliers only.
Loop:
- Randomly select the minimal sample size
(e.g., for a line). - Fit the model to those points.
- Find inliers: points within distance
of the model. - Repeat
times; keep the model with the most inliers. - (Optionally) refit with all inliers via least squares.
Number of iterations to guarantee with confidence
Pros / Cons:
| Pros | Cons |
|---|---|
| General (stitching, 2-view relations) | Needs parameter tuning ( |
| Works well in practice | Fails at low inlier ratio (too many iters) |
Hough vs. RANSAC: Hough votes globally (good for many instances, high-dim cost); RANSAC hypothesizes-then-verify (good for single best model with outliers).
5. Local Features / Interest Points
5.1 Why local features?
Pixel representation is not invariant to translation, illumination, scale, or viewpoint. Local features are:
- Locality — small image region; robust to clutter/occlusion.
- Repeatability — same feature found across transformed images.
- Distinctiveness — unique descriptor; minimizes wrong matches.
- Compactness/efficiency — far fewer than pixels.
Applications: recognition, image search, 3D reconstruction, tracking, panorama stitching.
5.2 What makes a good keypoint?
If you had to click a point, leave, and find it again after the image is deformed, you'd pick a corner, not a flat region or an edge (edges are ambiguous along their length).
| Region | Shift response |
|---|---|
| Flat | little change in any direction |
| Edge | change along one direction only (none along the edge) |
| Corner | large change in all directions |
Corners are the distinctive interest points we want.
6. Harris Corner Detector (Harris & Stephens 1988)
6.1 The math — SSD error
Shift a window
We want
6.2 Small-motion (first-order Taylor)
For small
So
where the second-moment matrix (structure tensor) is:
(
6.3 Interpreting via its eigenvalues
Classification by eigenvalues:
| Case | Meaning |
|---|---|
| Flat region | |
| Edge | |
| Corner |
6.4 Cornerness (response) function
Instead of eigen-decomposition, Harris uses:
with
| Classification | |
|---|---|
| Corner | |
| Edge | |
| $ | R |
This avoids computing eigenvalues (faster) while preserving the classification.
6.5 Harris algorithm
- Compute image derivatives
. - Compute squares and products:
. - Apply Gaussian filter (smooth the products).
- Compute corner response
; keep pixels with . - Non-maximum suppression: keep only local maxima of
.
Note: Harris corners are translation-invariant and partly illumination/rotation robust, but not scale-invariant — that is fixed later by the Harris-Laplace / SIFT scale-selection step (next chapter).
7. Chapter Summary
- Edges = extrema of gradient; use Sobel/DoG then Canny (NMS + hysteresis).
- Fit lines/circles via least squares (non-robust) or Hough (voting, multi-instance).
- RANSAC robustly fits a single model under heavy outliers.
- Harris detects repeatable, distinctive corners via the second-moment matrix
and response , followed by NMS.