Edd's Knowledge Base

A corner is a point where the image changes strongly in every direction. Corners are good landmarks: they can be located precisely and found again in another view of the same scene, which makes them the first step of image matching, tracking and 3D reconstruction. The Harris detector (Harris and Stephens, 1988) finds them from image gradients.

Intuition: Shift a Small Window

Slide a small window by and measure how much its contents change:

RegionWhat happens when the window shiftsVerdict
FlatNo change in any directionNot distinctive
EdgeNo change along the edge, large change across itAmbiguous along the edge
CornerLarge change in every directionDistinctive

The Structure Tensor

For small shifts the change is described by the structure tensor (second-moment matrix), built from the image derivatives (Image Gradients and the Sobel Operator) and summed over a window with weights :

The products , , are products of first derivatives, not second derivatives. The eigenvalues of tell the regions apart:

Region
smallsmallFlat
largesmallEdge
largelargeCorner

The Response Function

Computing eigenvalues per pixel is costly, so Harris uses a score that needs only the determinant and trace:

with built from the window sums, and to .

  • large and positive: corner.
  • negative: edge (one eigenvalue dominates).
  • small: flat region.

Algorithm

flowchart LR
    A[Gray image] --> B["Gradients Ix, Iy (Sobel)"]
    B --> C["Products Ix², Iy², IxIy"]
    C --> D["Sum over a window to get M"]
    D --> E["Response R = det M - k trace² M"]
    E --> F[Threshold]
    F --> G["Non-maximum suppression (3x3)"]
    G --> H[Corner list]
  1. Compute and (optionally after Gaussian smoothing).
  2. Form , and at every pixel.
  3. Sum each over a window (for example ) to get the entries of .
  4. Compute at every pixel.
  5. Threshold , then apply non-maximum suppression so each corner is one pixel instead of a blob (Non-Maximum Suppression).

Harris on a photograph with a box window and a threshold of 10% of the maximum response. 241 corners survive 3 x 3 suppression. The edge of the image also attracts corners, which is a border artifact (Image Borders and Padding).

Parameters

ParameterEffect
Window size and weightsLarger windows give smoother, more robust responses with slightly worse localization. A Gaussian window is smoother and more rotation-invariant than a box window.
Larger penalizes edges more and keeps fewer, stronger corners.
ThresholdControls how many corners are kept. It is best set relative to the maximum of , since the absolute scale depends on image contrast and can be around .
Pre-smoothing Suppresses noise-induced corners.

How the threshold sets the corner count (same photograph as above, 800 x 531, thresholds as a fraction of the maximum ):

ThresholdCorners after 3 x 3 NMS
1%about 2000
5%about 570
10%241
20%about 67

A common target is 100 to 300 corners per image.

Properties and Limits

  • Rotation invariant: the eigenvalues of do not change when the image rotates.
  • Robust to additive brightness change, since derivatives ignore a constant offset. Scaling contrast changes (it scales with the fourth power of the gain), which is why the threshold is relative.
  • Not scale invariant: a corner at one scale looks like a curved edge at a coarser one. Multi-scale detectors search over a scale space (Image Pyramids), and later detectors such as SIFT build on this idea (Scale Space and Difference of Gaussians).
  • Computation: a naive per-pixel loop with a window costs , and the box sums are a classic use of Integral Images.

Sources: Harris corner detector (Wikipedia); Harris and Stephens, A Combined Corner and Edge Detector, 1988. The threshold sweep is my own measurement on the example photograph.


Related: Computer Vision MOC, Image Gradients and the Sobel Operator, Non-Maximum Suppression, Corner Detection Snippets