Implementation:Kornia Kornia ScaleSpaceDetector
| Knowledge Sources | |
|---|---|
| Domains | Vision, Feature_Detection |
| Last Updated | 2026-02-09 15:00 GMT |
Overview
Concrete tool for differentiable multi-scale local feature detection provided by Kornia.
Description
ScaleSpaceDetector is a modular nn.Module that assembles 5 sub-modules: scale pyramid generator, response function (cornerness), soft non-maximum suppression, affine shape estimator, and orientation estimator. It detects keypoints as Local Affine Frames (LAFs) of shape (B, N, 2, 3) encoding position, scale, and orientation. The detector is differentiable, enabling end-to-end training of detection and description.
Usage
Initialize with desired number of features and optional custom sub-modules. Pass grayscale images to detect keypoints. Use with descriptor modules (HardNet, SIFTDescriptor) for matching.
Code Reference
Source Location
- Repository: kornia
- File:
kornia/feature/scale_space_detector.py - Lines: L72-264
Signature
class ScaleSpaceDetector(nn.Module):
def __init__(
self,
num_features: int = 500,
mr_size: float = 6.0,
scale_pyr_module: Optional[nn.Module] = None,
resp_module: Optional[nn.Module] = None,
nms_module: Optional[nn.Module] = None,
ori_module: Optional[nn.Module] = None,
aff_module: Optional[nn.Module] = None,
minima_are_also_good: bool = False,
scale_space_response: bool = False
) -> None
Forward
def forward(
self,
img: torch.Tensor,
mask: Optional[torch.Tensor] = None
) -> Tuple[torch.Tensor, torch.Tensor]
Import
from kornia.feature import ScaleSpaceDetector
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| img | torch.Tensor | Yes | Grayscale image tensor of shape (B, 1, H, W) |
| mask | Optional[torch.Tensor] | No | Valid region mask for restricting detection area |
Outputs
| Name | Type | Description |
|---|---|---|
| lafs | torch.Tensor (B, N, 2, 3) | Local Affine Frames encoding keypoint position, scale, and orientation |
| responses | torch.Tensor (B, N) | Detector response scores for each keypoint |
Usage Examples
Basic Detection
import torch
from kornia.feature import ScaleSpaceDetector
detector = ScaleSpaceDetector(num_features=500)
img = torch.rand(1, 1, 256, 256)
lafs, responses = detector(img)
# lafs.shape == (1, 500, 2, 3)
# responses.shape == (1, 500)
Detection with Custom Descriptor
import torch
from kornia.feature import ScaleSpaceDetector, HardNet, LAFDescriptor
detector = ScaleSpaceDetector(num_features=500)
descriptor = LAFDescriptor(HardNet())
img = torch.rand(1, 1, 256, 256)
lafs, responses = detector(img)
descriptors = descriptor(img, lafs)
# descriptors.shape == (1, 500, 128)