SIFT descriptor

A keypoint comes with a position and a scale. The SIFT descriptor turns the patch around it into 128 numbers that should stay the same when the image is rotated, scaled or lit differently. Pick a keypoint, follow it through the steps, and transform the image to see how well the numbers hold.

Transformed image and keypoints keypoints and orientation selected
1 · Gradients around the keypoint gradients, weighted 4 × 4 cells orientation window
2 · Orientation histogram 80% of the peak θ
3 · 4 × 4 histograms of 8 orientations transformed original
4 · The 128 values normalized clamp limit clamped and renormalized original image

What a descriptor should do

Detection gives each keypoint a position and a scale, for example from the Difference of Gaussians. The descriptor extracts a vector from the patch around it that is robust: it stays nearly the same when the patch is seen again under a different viewpoint or light, and distinctive: different patches give different vectors. It should also be compact and fast to compute and compare. Most descriptors are templates, histograms, or combinations of both, and most use edge and gradient information, which captures texture; color is rarely used. SIFT is a set of local histograms of oriented gradients.

The steps

  1. Gradients. The gradient magnitude and orientation are computed on the Gaussian image LL closest to the keypoint's scale: m=Lx2+Ly2m = \sqrt{L_x^2 + L_y^2}, ϕ=atan2⁡(Ly,Lx)\phi = \operatorname{atan2}(L_y, L_x).
  2. Orientation estimation. A histogram of 36 bins of 10° collects the orientations within a radius of 3⋅1.5σ3 \cdot 1.5\sigma, each weighted by its magnitude and a Gaussian of 1.5σ1.5\sigma. The highest peak gives the dominant orientation θ\theta, refined with a parabola through three bins. Every other peak of at least 80% of the highest creates an extra keypoint with its own orientation.
  3. Normalize the orientation. The patch is rotated so that θ\theta points along the x axis: a grid of 16 × 16 samples is laid out in the keypoint's frame, rotated by θ\theta, with a spacing proportional to σ\sigma. Every orientation is measured relative to θ\theta.
  4. Histograms. The grid is divided into 4 × 4 subregions of 4 × 4 samples. Each subregion gets a histogram of 8 orientations, 45° each. Each sample votes with its gradient magnitude, weighted by a Gaussian over the window, so gradients near the center count more. Votes are split between neighboring subregions and bins, so a small shift or rotation changes the histograms gradually.
  5. Vector. The 4 × 4 × 8 = 128 values are lined up into one vector.

Illumination

Two steps make the descriptor robust to changes of brightness I+bI + b and contrast αI\alpha I:

Non-linear illumination effects, such as saturation or specular highlights, can make a few gradients very large, and those would then dominate the whole descriptor. So all values above 0.2 are clamped to 0.2, and the vector is normalized again. The descriptor then depends less on the exact magnitudes and more on the distribution of orientations.

In practice

The same keypoint in the transformed image is described at the mapped position and scale, which is known here, so only the descriptor is tested and not the detector. Efficient implementations compute the oriented histograms with steerable filters, filters whose orientation can be set to that of each histogram bin. SURF is a fast approximation of the same idea with box filters on integral images, about six times faster at similar quality. How the vectors are compared is the topic of matching and the ratio test.

Try this