kornia.feature

corner_harris(input: torch.Tensor, k: torch.Tensor) → torch.Tensor[source]

Computes the Harris corner detection.

See CornerHarris for details.

non_maxima_suppression2d(input: torch.Tensor, kernel_size: Tuple[int, int]) → torch.Tensor[source]

Applies non maxima suppression to filter.

See NonMaximaSuppression2d for details.

class CornerHarris(k: torch.Tensor)[source]

Computes the Harris corner detection.

The response map is computed according the following formulation:

\[R = det(M) - k \cdot trace(M)^2\]

where:

\[\begin{split}M = \sum_{(x,y) \in W} \begin{bmatrix} I^{2}_x & I_x I_y \\ I_x I_y & I^{2}_y \\ \end{bmatrix}\end{split}\]

and \(k\) is an empirically determined constant \(k ∈ [ 0.04 , 0.06 ]\)

Parameters:k (torch.Tensor) – the Harris detector free parameter.
Returns:the response map per channel.
Return type:torch.Tensor
Shape:
  • Input: \((B, C, H, W)\)
  • Output: \((B, C, H, W)\)

Examples

>>> input = torch.tensor([[[
    [0., 0., 0., 0., 0., 0., 0.],
    [0., 1., 1., 1., 1., 1., 0.],
    [0., 1., 1., 1., 1., 1., 0.],
    [0., 1., 1., 1., 1., 1., 0.],
    [0., 1., 1., 1., 1., 1., 0.],
    [0., 1., 1., 1., 1., 1., 0.],
    [0., 0., 0., 0., 0., 0., 0.],
]]])  # 1x1x7x7
>>> # compute the response map
>>> output = kornia.feature.CornerHarris()(input)
tensor([[[[0., 0., 0., 0., 0., 0., 0.],
          [0., 1., 0., 0., 0., 1., 0.],
          [0., 0., 0., 0., 0., 0., 0.],
          [0., 0., 0., 0., 0., 0., 0.],
          [0., 0., 0., 0., 0., 0., 0.],
          [0., 1., 0., 0., 0., 1., 0.],
          [0., 0., 0., 0., 0., 0., 0.]]]])
class NonMaximaSuppression2d(kernel_size: Tuple[int, int])[source]

Applies non maxima suppression to filter.