Skip to content

SIFT

Fact Value
Also called SIFT-inspired scale-space keypoints, Scale-invariant feature transform
Status Implemented and tested
Family Texture, corners, blobs and features
Engine Science engine
Type Nonlinear, spatial, difference of Gaussians extrema with orientation
Output Features
Operator shown as algorithm (simplified)
Support radius global
Code engine/src/pixelnexus_engine/filters/keypoints.py, sift
Operator code engine/src/pixelnexus_engine/filters/keypoints.py, keypoint_representation
Packages OpenCV

Overview

SIFT, the scale-invariant feature transform of Lowe, finds keypoints that stay the same when the image is scaled or turned. It looks for blobs of any size in a difference-of-Gaussians scale space, refines their position and size, drops weak points and points on edges, and gives each one an orientation. The keypoints go to the Features panel and are drawn on the canvas. Only the detector runs, not the descriptor. The filter runs in the PixelNexus engine, with OpenCV.

Four panels: a Siemens star with 36 spokes, and SIFT keypoints as rings with angle lines. On the star, small rings sit only near the rim, where the spokes meet the gray ground. The turned star shows the same rings in the turned places. On the Disks image, large rings fill the disks, several with many angle lines from one center. Four panels: a Siemens star with 36 spokes, and SIFT keypoints as rings with angle lines. On the star, small rings sit only near the rim, where the spokes meet the gray ground. The turned star shows the same rings in the turned places. On the Disks image, large rings fill the disks, several with many angle lines from one center.
The keypoints with the defaults on the Siemens star, on the star turned a quarter counterclockwise, and on the Disks image. Each keypoint is a ring of its radius with a line along its angle.

How it works

  1. Build the difference-of-Gaussians scale space, octave by octave.
  2. Find points that beat their 26 neighbors, and refine them.
  3. Drop weak points and points on edges.
  4. Give each point the main direction of its gradients.

Mathematical foundation

\[ D(x, \sigma) = (G_{k\sigma} - G_\sigma) * I, \qquad k = 2^{1/3}, \qquad \frac{\operatorname{tr}(H)^2}{\det H} < \frac{(r + 1)^2}{r},\quad r = 10 \]

The formula shows the default parameter values.

where

  • \(D\): The difference of Gaussians
  • \(k\): The scale step within an octave
  • \(H\): The 2 x 2 Hessian of D
  • \(r\): The edge threshold
  • \(x, y\): The keypoint position, with the center of the top-left pixel at 0, 0
  • \(\theta\): The orientation, counterclockwise from the x axis

SIFT builds a scale space of Gaussian blurs, k times wider at each step, and takes the differences D of neighboring blurs. These approximate the scale-normalized Laplacian. A keypoint is a point of D that is larger or smaller than its 26 neighbors in position and scale. Its position and scale are refined by fitting a quadratic, and weak points are dropped. Points on edges, where the Hessian H of D has one curvature much larger than the other, are dropped too. The orientation is the peak of a histogram of gradient directions around the point. Other peaks within 80 percent of the highest give more keypoints at the same place.

A Gaussian scale space blurs the image more and more. SIFT groups the blurs into octaves, where the blur doubles, with a fixed number of layers in each. The difference of two neighboring blurs approximates the scale-normalized Laplacian, so blobs give extrema. A candidate is a point larger or smaller than all 26 neighbors in position and scale.

Each candidate is refined by fitting a quadratic to D around it. Points whose refined value is too small are dropped, since they sit in flat areas. Points on edges are dropped too. Along an edge, D bends much more across than along, so the ratio tr(H)^2 / det H of the curvatures is large. Finally, a histogram of 36 gradient directions around the point gives its orientation. Each peak within 80 percent of the highest gives one more keypoint at the same place.

Kernel or operator

The Inspector asks the engine for the stages with the current settings. They start with the 8-bit luma and follow the detector step by step. They summarize what OpenCV does, so the label is Simplified.

Parameters

Parameter Default Values Meaning
Most keypoints maxFeatures 0 0 to 5000 Keep at most this many keypoints, the strongest. 0 keeps all.
Layers per octave octaveLayers 3 1 to 8 The number of scales in each octave, where the size doubles. Lowe uses 3.
Contrast threshold contrastThreshold 0.04 0.001 to 0.2 Weak extrema in flat areas are dropped. OpenCV divides this by the number of layers.
Edge threshold edgeThreshold 10 1 to 50 The largest ratio r of the two curvatures. Points on edges, where one curvature is much larger, are dropped. Lowe uses 10.
Sigma sigma 1.6 0.5 to 5 px The blur of the first scale. Lowe uses 1.6.

Implementation

sift in engine/src/pixelnexus_engine/filters/keypoints.py calls cv2.SIFT_create with the catalog values and detect on the 8-bit luma. Each keypoint becomes a row with x, y, the radius (half of OpenCV's size), the angle, the score (OpenCV's response) and the octave. SIFT packs octave, layer and scale into one number, so the octave is its lowest byte, read as a signed number.

OpenCV puts the center of the top-left pixel at 0, 0, as the feature tables do, so positions keep their fraction. OpenCV measures angles clockwise in image coordinates, where y points down. The table turns them to count counterclockwise from the x axis, as (360 - angle) mod 360. The rows are sorted by score. With a selection, the detector still looks at the whole image, and only the keypoints on selected pixels are kept.

Worked example

Image Keypoints Radius (px) Found after a quarter turn (%)
Siemens star 58 1.1 to 13.7 83
Disks 46 3.8 to 45.2 72

SIFT with the defaults on the 512 x 512 test images. The last column is the share of keypoints found again after the image is turned a quarter counterclockwise: within 1 pixel of the turned place, with a radius within 10 percent, and with an angle 90 degrees larger, within 5 degrees. A quarter turn moves pixels exactly onto pixels, so any loss comes from the detector itself.

Complexity

  • Time: \(O(N)\)
  • Memory: \(O(N)\)

N is the number of pixels. The octaves shrink by 4 in area, so all of them together cost about 4/3 of the first.

Artifacts and limitations

Limitations

  • Slower than ORB and AKAZE.
  • Fine repeated detail can give no keypoints at all. On the Siemens star, all of them lie more than 205 pixels from the center, near the rim.
  • Only the detector runs. The 128-number descriptors are not computed.

Artifacts

  • Two keypoints at the same place with different angles, where a point has two strong directions.

Tests

The table must hold what cv2.SIFT_create finds, with the angle turned to count counterclockwise, sorted by score. After a quarter turn of the Siemens star, at least 80 percent of the keypoints must come back at the turned place with an angle 90 degrees larger. This test is what proves the direction of the angles. The octave must be the signed lowest byte. A flat image must give no keypoints, and runs must repeat exactly. The engine API tests check the JSON and the stages.

References

  • Lowe, D. G. Distinctive image features from scale-invariant keypoints. International Journal of Computer Vision 60(2), 91 to 110, 2004. DOI 10.1023/B:VISI.0000029664.99615.94.
  • OpenCV documentation, cv2.SIFT_create and detect.