Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

docs(feature): clarify SIFT recipes and descriptor interfaces (#5750)

Dmytro Mishkin0ba5356bf201
diff --git a/changelog.d/5750.added.md b/changelog.d/5750.added.md
new file mode 100644
index 000000000..5ec320192
--- /dev/null
+++ b/changelog.d/5750.added.md
@@ -0,0 +1,4 @@
+Document an explicit scale-space pyramid SIFT recipe, distinguish multiresolution detection
+from scale-space detection, and explain the patch, dense and supplied-frame descriptor interfaces.
+Document the repaired multiresolution pyramid orientation and its remaining validation and
+possible-deprecation criteria without changing defaults, adding runtime warnings or removing APIs.
diff --git a/docs/source/feature.descriptors.rst b/docs/source/feature.descriptors.rst
index cb9486585..47e916b7a 100644
--- a/docs/source/feature.descriptors.rst
+++ b/docs/source/feature.descriptors.rst
@@ -3,6 +3,64 @@ Descriptors
.. currentmodule:: kornia.feature
+.. _sift-descriptor-interfaces:
+
+Choosing a SIFT descriptor interface
+------------------------------------
+
+These interfaces serve different inputs and outputs; none detects keypoints.
+For detection and description together, use the :ref:`SIFT pipeline guide <sift-pipelines>`.
+
+.. list-table:: SIFT descriptor contracts
+ :header-rows: 1
+ :widths: 25 35 40
+
+ * - Interface
+ - Input
+ - Output and purpose
+ * - :class:`SIFTDescriptor`
+ - Canonically sampled grayscale patches ``(N, 1, patch_size, patch_size)``.
+ - One descriptor per patch, ``(N, 128)`` with default bins. Use when patch
+ extraction, scale normalization and orientation have already been handled.
+ * - :class:`DenseSIFTDescriptor`
+ - A grayscale image ``(B, 1, H, W)``.
+ - A dense descriptor map ``(B, 128, H_out, W_out)`` with default bins.
+ Spatial size depends on bin size, stride and padding.
+ * - :class:`SIFTDescriptorFromPyramid`
+ - A grayscale image and supplied, already oriented LAFs ``(B, N, 2, 3)``.
+ - Sparse descriptors ``(B, N, 128)`` with default bins, sharing image-gradient
+ histograms between frames. ``forward(image, lafs)`` preserves their orientation.
+
+All three support RootSIFT normalization. They return kornia's angle-major layout;
+:func:`convert_sift_descriptor_layout` reorders bins to OpenCV's layout. Layout
+conversion does not make differently sampled descriptors numerically equivalent.
+The converter expects the descriptor dimension last. For a dense map, move its
+channels last before conversion and restore them afterwards::
+
+ opencv_dense = convert_sift_descriptor_layout(
+ dense.movedim(1, -1), "kornia", "opencv"
+ ).movedim(-1, 1)
+
+:class:`SIFTDescriptorFromPyramid` builds its own pyramid rather than reusing a
+detector's Gaussian layers. It constructs histogram maps only for octaves used by
+valid supplied frames, which can reduce work and memory for frames concentrated
+in a few octaves. See the recorded
+`octave-selection measurements <https://github.com/kornia/kornia/blob/main/benchmarks/feature/sift_summary.md#review-follow-up-descriptor-octave-selection>`_.
+General affine frames use an approximate angular remapping and spatial pooling;
+this is not numerically identical to patch extraction.
+
+Its ``orient_and_describe(image, lafs)`` method additionally estimates orientation.
+The automatic orientation used by ``SIFTFeature(descriptor_backend="pyramid")``
+was repaired in `#5762 <https://github.com/kornia/kornia/pull/5762>`_ by integrating
+smoothed gradients before angular binning. `#5748 <https://github.com/kornia/kornia/issues/5748>`_
+remains open for its performance and accuracy acceptance criteria. That validation
+does not invalidate the descriptor-only ``forward`` use on supplied oriented LAFs.
+The :ref:`validation and possible deprecation plan <sift-pipelines>` retains all
+three standalone descriptor interfaces.
+
+API reference
+-------------
+
.. autoclass:: DenseSIFTDescriptor
:members: get_gradient_histograms
diff --git a/docs/source/feature.local_features.rst b/docs/source/feature.local_features.rst
index c17e06825..329bc90a0 100644
--- a/docs/source/feature.local_features.rst
+++ b/docs/source/feature.local_features.rst
@@ -3,6 +3,124 @@ Local features (detector and descriptor together)
.. currentmodule:: kornia.feature
+.. _sift-pipelines:
+
+Choosing a SIFT pipeline
+------------------------
+
+For new scale-space SIFT pipelines, start with
+:class:`SIFTFeatureScaleSpace` and explicitly select ``descriptor_backend="pyramid"``::
+
+ import kornia.feature as KF
+
+ feature = KF.SIFTFeatureScaleSpace(
+ num_features=2048, descriptor_backend="pyramid", rootsift=True
+ ).to(grayscale_image.device)
+ lafs, responses, descriptors = feature(grayscale_image)
+
+``grayscale_image`` is a floating-point tensor of shape ``(B, 1, H, W)`` with values
+in ``[0, 1]``. Outputs are LAFs ``(B, N, 2, 3)``, responses ``(B, N)`` and descriptors
+``(B, N, 128)``. ``N`` is the requested feature budget; fewer detections leave padded
+slots. Use :func:`laf_is_filled` to identify real detections before matching.
+``rootsift=True`` selects RootSIFT normalization. Use ``descriptor_layout="opencv"``
+when feeding descriptors to :class:`LightGlueMatcher` with ``"sift"``.
+
+This is an explicit recipe: both feature classes still default to
+``descriptor_backend="patch"``. No constructor default or numerical behavior is
+changed by this recommendation. Backend performance depends on device, image size,
+feature count and batching; the recipe is not a claim that pyramid extraction is
+always faster.
+
+.. list-table:: SIFT pipeline choices
+ :header-rows: 1
+ :widths: 25 45 30
+
+ * - Pipeline
+ - Detection and extraction
+ - When to use it
+ * - ``SIFTFeatureScaleSpace(..., descriptor_backend="pyramid")``
+ - Dedicated DoG scale-space detector; orientation and description share the
+ detector's Gaussian layers.
+ - Primary recipe for new scale-space SIFT use.
+ * - ``SIFTFeatureScaleSpace(..., descriptor_backend="patch")``
+ - Generic :class:`ScaleSpaceDetector`; orientation and description operate on
+ resampled patches.
+ - Existing pipelines, or workloads where measurements favor patch extraction.
+ * - ``SIFTFeature(..., descriptor_backend="patch")``
+ - Multiresolution, per-level DoG detection; patch orientation and description.
+ - Existing multiresolution pipelines; this is an approximation to scale-space SIFT.
+ * - ``SIFTFeature(..., descriptor_backend="pyramid")``
+ - The same multiresolution detector; a separate image pyramid supplies smoothed
+ gradients for orientation and pooled histogram maps for description.
+ - Its automatic orientation was repaired in #5762. Use it for measured
+ multiresolution workloads; #5748 remains open for the validation below.
+
+The two feature classes have different detector algorithms. :class:`SIFTFeature`
+applies a single-scale DoG response independently at each image resolution, with
+2-D non-maximum suppression. It does not select extrema across scale or refine
+positions and scales to subpixel precision. :class:`SIFTFeatureScaleSpace` searches
+3-D DoG scale-space extrema and refines their positions and scales. Neither preset
+implements classical SIFT's contrast and Hessian edge rejection, and each assigns
+only one orientation per detection (or preserves upright frames when requested).
+
+``descriptor_backend`` is not an interchangeable descriptor switch. In
+:class:`SIFTFeature` it changes orientation and description but keeps detection;
+in :class:`SIFTFeatureScaleSpace` it also selects a different detector implementation.
+Consequently, the scale-space backends can return different detections as well as
+different descriptors.
+
+The scale-space pyramid path ranks valid refined extrema by absolute response.
+Precise doubling and integer octave decimation keep pixel coordinates aligned.
+The converged integer Gaussian layer and refined continuous scale are retained
+separately. Gradients are computed once per used layer and shared between orientation
+and description; no pyramid is retained between calls. Sampling and Gaussian support
+differ from patch extraction, so descriptors are not numerically interchangeable.
+For this backend, ``compile_modules`` accepts ``scale_pyr`` and ``subpix`` (or
+``True`` for both); sparse orientation and description run eagerly. The patch
+backend retains the generic detector's compilation options.
+
+Matching with LightGlue
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Use ``descriptor_layout="opencv"`` with :class:`LightGlueMatcher` in ``"sift"``
+mode. Pass the oriented LAFs returned by the feature, filter zero-LAF padding from
+both LAFs and descriptor rows with :func:`laf_is_filled`, and supply the original
+image sizes as ``hw1=(height0, width0)`` and ``hw2=(height1, width1)``. The matcher
+converts the LAF angle and scale internally; do not apply those conversions twice.
+
+The public adapter uses one sixth of the LAF scale. For the scale-space presets'
+6-sigma frames this is the detection sigma. :class:`SIFTFeature` uses a different
+measurement-region convention, so its multiresolution frames do not imply the same
+detection sigma. Descriptor-layout compatibility alone does not guarantee equal
+matching accuracy across the four pipelines. Evaluate the complete feature/matcher
+combination at the intended feature budget.
+
+Validation and possible deprecation
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+`#5762 <https://github.com/kornia/kornia/pull/5762>`_ repaired the automatic
+orientation used by ``SIFTFeature(descriptor_backend="pyramid")``. It integrates
+a 19x19 support of smoothed image gradients before angular binning, without
+extracting image patches. The issue tracked in
+`#5748 <https://github.com/kornia/kornia/issues/5748>`_ remains open: its
+acceptance criteria include performance at 1024 features and Oxford accuracy at
+2048 features. Promotion of this convenience combination requires recovered
+accuracy and a demonstrated runtime or memory advantage on a stated workload.
+Validation should compare with the patch backend at 1024 and 2048 features on
+IMC PhotoTourism pose estimation and Oxford homography estimation, reporting
+matcher settings, device and timing methodology.
+
+If repair does not establish those benefits, the plan is to deprecate this
+convenience combination and remove it only after the :doc:`API stability policy
+</get-started/stability>` window: at least one minor release of warnings and a
+documented replacement. No formal deprecation warning or removal version is
+introduced here. This plan concerns the combination, not the standalone
+:class:`SIFTDescriptorFromPyramid` descriptor-only interface; see
+:ref:`sift-descriptor-interfaces`.
+
+API reference
+-------------
+
.. autoclass:: LocalFeature
:members: forward
@@ -35,40 +153,10 @@ Local features (detector and descriptor together)
:undoc-members:
:members: x, y, to
-.. autoclass:: SIFTFeature
+.. autoclass:: SIFTFeatureScaleSpace
:members: forward
-``SIFTFeature(descriptor_backend="pyramid")`` uses shared image-pyramid maps
-without extracting image patches. Orientation integrates a smoothed gradient
-field before angular binning, separately from the descriptor histogram maps.
-The default orientation histogram and global descriptor maps each have 36 bins,
-with independent resolutions. Descriptor maps are pooled with separable tent
-filters and remapped into 8 angular bins per local spatial cell. Both stages share
-the image pyramid, which is built independently of the detector. The default
-``patch`` backend is unchanged.
-
-The scale-space SIFT preset supports ``descriptor_backend="pyramid"`` for
-specialized sparse extraction from the detector's Gaussian pyramid::
-
- feature = kornia.feature.SIFTFeatureScaleSpace(
- num_features=4096, descriptor_backend="pyramid"
- )
- lafs, responses, descriptors = feature(grayscale_image)
-
-This path uses a dedicated DoG detector, with strict sparse extrema, iterative
-subpixel refinement, and top-K ranking by absolute response. It applies neither
-contrast nor edge rejection. Precise doubling and integer octave decimation keep
-pixel coordinates aligned. The converged integer Gaussian layer and refined
-continuous scale are retained separately. Gradients are computed once per used
-layer and shared between orientation and description. It returns one descriptor per detection and the same fixed feature
-budget as the default patch backend. Its sampling and Gaussian support differ
-from patch extraction, so descriptors are not numerically interchangeable.
-No pyramid is retained between calls. For this backend, ``compile_modules``
-accepts ``scale_pyr`` and ``subpix`` (or ``True`` for both); sparse orientation
-and description run eagerly. The default ``patch`` backend retains the existing
-generic detector and its compilation options.
-
-.. autoclass:: SIFTFeatureScaleSpace
+.. autoclass:: SIFTFeature
:members: forward
.. autoclass:: GFTTAffNetHardNet
diff --git a/docs/source/feature.rst b/docs/source/feature.rst
index f2882f6f3..265db01a7 100644
--- a/docs/source/feature.rst
+++ b/docs/source/feature.rst
@@ -9,6 +9,9 @@ kornia.feature
Local feature detection, description and matching, from classical operators to pretrained models, all as
differentiable PyTorch modules. For guidance on which model to pick, see the
:doc:`image matching guide </applications/image_matching>`.
+For classical SIFT, start with the explicit scale-space pyramid recipe in the
+:ref:`SIFT pipeline guide <sift-pipelines>`. For supplied patches or frames, see
+the :ref:`SIFT descriptor interfaces <sift-descriptor-interfaces>`.
.. list-table::
:widths: 30 70
@@ -16,9 +19,11 @@ differentiable PyTorch modules. For guidance on which model to pick, see the
* - :doc:`feature.detectors`
- Keypoint detectors: Harris, GFTT, Hessian, DoG responses and the KeyNet, scale-space and multi-resolution detectors.
* - :doc:`feature.descriptors`
- - Patch descriptors: SIFT, MKD, HardNet, HardNet8, HyNet, TFeat, SOSNet, and the SOLD2 line descriptor.
+ - Patch, dense and supplied-frame SIFT descriptors; MKD, HardNet, HardNet8, HyNet, TFeat, SOSNet,
+ and the SOLD2 line descriptor.
* - :doc:`feature.local_features`
- - Detector + descriptor pipelines: DISK, ALIKED, DeDoDe, XFeat, SIFTFeature, KeyNetAffNetHardNet and friends.
+ - Detector + descriptor pipelines: DISK, ALIKED, DeDoDe, XFeat, SIFTFeatureScaleSpace,
+ SIFTFeature, KeyNetAffNetHardNet and friends.
* - :doc:`feature.matching`
- Nearest-neighbour, mutual, ratio-test, FGINN and AdaLAM matching; LightGlue and LoFTR.
* - :doc:`feature.laf`
diff --git a/kornia/feature/integrated.py b/kornia/feature/integrated.py
index 4626e75b7..a384dae2e 100644
--- a/kornia/feature/integrated.py
+++ b/kornia/feature/integrated.py
@@ -322,28 +322,37 @@ class _SIFTFeature(LocalFeature):
class SIFTFeature(_SIFTFeature):
- """Convenience module, which implements DoG detector + (Root)SIFT descriptor.
+ """Multiresolution DoG detection followed by a (Root)SIFT descriptor.
+
+ :class:`~kornia.feature.MultiResolutionDetector` applies a single-scale DoG response
+ independently at each image resolution and uses 2-D non-maximum suppression. It does
+ not select extrema across scale or refine positions and scales to subpixel precision.
+ It does not apply classical SIFT's contrast or Hessian edge rejection and assigns one
+ orientation per detection unless ``upright=True``. For new scale-space SIFT pipelines,
+ start with :class:`SIFTFeatureScaleSpace` and explicitly select
+ ``descriptor_backend="pyramid"``; see :ref:`sift-pipelines`.
``descriptor_backend="pyramid"`` uses :class:`SIFTDescriptorFromPyramid` for
orientation and description at the detector's sparse LAFs. Detection and the
- feature budget are unchanged. The default ``"patch"`` backend retains the
+ feature budget are unchanged. Its orientation integrates smoothed image
+ gradients before angular binning without extracting image patches. The
+ remaining performance and accuracy acceptance criteria are tracked in
+ `#5748 <https://github.com/kornia/kornia/issues/5748>`_. No deprecation warning
+ or removal version is set.
+ The standalone descriptor-only ``SIFTDescriptorFromPyramid.forward`` interface
+ remains useful for supplied oriented LAFs. The default ``"patch"`` backend retains the
existing patch-wise pipeline. Both return descriptors in kornia's SIFT layout by
default; ``descriptor_layout="opencv"`` returns them in OpenCV's, which
:class:`~kornia.feature.LightGlueMatcher` expects with ``"sift"``.
:func:`~kornia.feature.convert_sift_descriptor_layout` converts between the two.
- The detector is :class:`~kornia.feature.MultiResolutionDetector` on the magnitude of a single-scale
- :class:`~kornia.feature.BlobDoGSingle` response. Like the DoG detectors of Lowe, OpenCV and VLFeat, it keeps
- both signs of DoG extremum: the maxima (dark blobs) and the minima (bright blobs). A keypoint is a strict
- maximum of the magnitude over its ``config["nms_size"]`` window (15 px by default) on its pyramid level, so a
- stronger response of the other sign in that window suppresses a weaker extremum, be it the ring of opposite
- sign around a blob or a nearby blob of the other polarity. Those detectors instead test a maximum against its
- 3x3x3 scale-space neighbours and a minimum likewise, so an extremum of one sign never suppresses one of the
- other. ``responses`` holds the magnitude.
-
- Using `kornia.feature.MultiResolutionDetector` without blur pyramid Still not as good as OpenCV/VLFeat because of
- https://github.com/kornia/kornia/pull/884,
- but we are working on it
+ The detector applies :class:`~kornia.feature.MultiResolutionDetector` to the
+ magnitude of a single-scale :class:`~kornia.feature.BlobDoGSingle` response.
+ It retains extrema of both polarity: dark blobs are DoG maxima and bright
+ blobs are DoG minima. On each image-pyramid level, a keypoint is a strict
+ maximum of response magnitude in its ``config["nms_size"]`` window (15 pixels
+ by default); a stronger extremum of either polarity in that window suppresses
+ a weaker one. ``responses`` contains the magnitude.
"""
def __init__(
@@ -388,21 +397,27 @@ class SIFTFeature(_SIFTFeature):
class SIFTFeatureScaleSpace(LocalFeature):
- """Convenience module, which implements DoG detector + (Root)SIFT descriptor.
+ """DoG scale-space detection, position/scale refinement and (Root)SIFT description.
- The default patch backend uses `kornia.feature.ScaleSpaceDetector`. Select
- ``descriptor_backend="pyramid"`` for a specialized SIFT pipeline that reuses
+ For new scale-space SIFT pipelines, explicitly select ``descriptor_backend="pyramid"``;
+ see :ref:`sift-pipelines`. The constructor default remains ``"patch"`` and uses
+ :class:`~kornia.feature.ScaleSpaceDetector`. The pyramid backend is a specialized SIFT pipeline that reuses
the detector's Gaussian images and each detection's octave and layer. Image
gradients are computed once per used layer and sampled for sparse orientation
and descriptor integration. A dedicated DoG detector refines only sparse
extrema and ranks all valid candidates by response, without contrast or edge
- rejection. The feature budget is unchanged; detections may differ.
+ rejection. Both backends search 3-D DoG extrema and refine position and scale;
+ neither applies classical SIFT's contrast or Hessian edge rejection, and each
+ assigns only one orientation per detection unless ``upright=True``. The backend
+ selects a different detector implementation as well as different orientation and
+ description stages. The feature budget is unchanged; detections may differ.
The default ``"patch"`` backend retains patch-wise orientation and description.
Both return descriptors in kornia's SIFT layout by default; ``descriptor_layout="opencv"``
returns them in OpenCV's, which :class:`~kornia.feature.LightGlueMatcher` expects with
``"sift"``. :func:`~kornia.feature.convert_sift_descriptor_layout` converts between the two.
- Still not as good as OpenCV/VLFeat because of https://github.com/kornia/kornia/pull/884, but we are working on it
+ Pyramid extraction is not guaranteed to be faster on every device or workload.
+ Patch extraction remains available for existing pipelines and measured performance needs.
"""
def __init__(
diff --git a/kornia/feature/sift/pyramid.py b/kornia/feature/sift/pyramid.py
index bf71c8540..e16e30a41 100644
--- a/kornia/feature/sift/pyramid.py
+++ b/kornia/feature/sift/pyramid.py
@@ -53,6 +53,15 @@ class SIFTDescriptorFromPyramid(nn.Module):
sharing one pyramid between orientation assignment and description. The
pyramid belongs to this descriptor; it is not reused from the detector.
+ Automatic orientation was repaired in
+ `#5762 <https://github.com/kornia/kornia/pull/5762>`_. The remaining
+ performance and accuracy acceptance criteria are tracked in
+ `#5748 <https://github.com/kornia/kornia/issues/5748>`_. The descriptor-only
+ ``forward(image, lafs)`` uses supplied oriented frames without estimating
+ their orientation. See
+ :ref:`sift-descriptor-interfaces` for the distinct patch, dense-map and
+ supplied-frame descriptor contracts.
+
The module combines the shared histogram maps of `VLFeat DSIFT
<https://www.vlfeat.org/api/dsift.html>`_ with orientation-relative spatial and
angular binning as in OpenCV's `SIFT implementation