MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Harris.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Features.hpp"
4
5/**
6 * @file Harris.hpp
7 * @brief Harris corner detection and non-maximum suppression.
8 *
9 * Pure functions. No MayaFlux type dependencies.
10 *
11 * ## Conventions
12 * - Input is single-channel normalised float in [0, 1]
13 * - w and h are pixel dimensions; caller ensures span size == w * h
14 * - Response map is normalised to [0, 1] by observed peak
15 * - Keypoint positions are normalised to [0, 1]
16 * - Parallelism handled internally via Parallel::par_unseq
17 */
18
20
21/**
22 * @brief Compute the Harris corner response map.
23 *
24 * For each pixel computes R = det(M) - k * trace(M)^2 where M is the
25 * structure tensor accumulated over a sigma-weighted window. Negative
26 * responses are clamped to 0. Output is normalised to [0, 1] by the
27 * observed peak response.
28 *
29 * Structure tensor gradients are computed via a 3x3 Sobel operator.
30 * The tensor is smoothed with a Gaussian of standard deviation sigma
31 * before computing det and trace.
32 *
33 * @param gray Single-channel float span, size must be w * h.
34 * @param w Image width in pixels.
35 * @param h Image height in pixels.
36 * @param k Harris sensitivity parameter. Typical range [0.04, 0.06].
37 * @param sigma Gaussian smoothing sigma for structure tensor. Must be > 0.
38 * @return Response map float vector of length w * h, values in [0, 1].
39 */
40[[nodiscard]] MAYAFLUX_API std::vector<float> harris_response(
41 std::span<const float> gray, uint32_t w, uint32_t h,
42 float k = 0.04F, float sigma = 1.0F);
43
44/**
45 * @brief Compute the Harris corner response map into caller-supplied buffers.
46 *
47 * Writes the normalised response into @p dst. Intermediate buffers
48 * dx/dy/tmp/ixx/iyy/ixy/sxx/syy/sxy must each be size >= w * h and
49 * must not alias each other or @p gray.
50 *
51 * @param gray Single-channel float span, size w * h.
52 * @param dx Scratch: horizontal gradient, size >= w * h.
53 * @param dy Scratch: vertical gradient, size >= w * h.
54 * @param tmp Scratch: filter horizontal pass, size >= w * h.
55 * @param ixx Scratch: structure tensor Ixx, size >= w * h.
56 * @param iyy Scratch: structure tensor Iyy, size >= w * h.
57 * @param ixy Scratch: structure tensor Ixy, size >= w * h.
58 * @param sxx Scratch: smoothed Sxx, size >= w * h.
59 * @param syy Scratch: smoothed Syy, size >= w * h.
60 * @param sxy Scratch: smoothed Sxy, size >= w * h.
61 * @param dst Output response map, size >= w * h, values in [0, 1].
62 * @param w Image width in pixels.
63 * @param h Image height in pixels.
64 * @param k Harris sensitivity parameter. Typical range [0.04, 0.06].
65 * @param kern Precomputed 1D Gaussian kernel for structure tensor smoothing.
66 */
67MAYAFLUX_API void harris_response(
68 std::span<const float> gray,
69 std::span<float> dx, std::span<float> dy, std::span<float> tmp,
70 std::span<float> ixx, std::span<float> iyy, std::span<float> ixy,
71 std::span<float> sxx, std::span<float> syy, std::span<float> sxy,
72 std::span<float> dst,
73 uint32_t w, uint32_t h,
74 float k,
75 std::span<const float> kern);
76
77/**
78 * @brief Extract peaks from a response map via non-maximum suppression.
79 *
80 * A pixel is a peak if its response exceeds threshold and it is the
81 * strict maximum within a square window of half-size nms_radius.
82 * Ties are broken in favour of the pixel with the lower raster index.
83 *
84 * Returned Keypoints are sorted by descending response.
85 *
86 * @param response Response map span, size must be w * h, values in [0, 1].
87 * @param w Image width in pixels.
88 * @param h Image height in pixels.
89 * @param threshold Minimum response value to consider. In [0, 1].
90 * @param nms_radius Non-maximum suppression half-window size in pixels.
91 * @return Keypoints sorted by descending response.
92 */
93[[nodiscard]] MAYAFLUX_API std::vector<Keypoint> extract_peaks(
94 std::span<const float> response, uint32_t w, uint32_t h,
95 float threshold, uint32_t nms_radius);
96
97} // namespace MayaFlux::Kinesis::Vision
uint32_t h
Definition InkPress.cpp:28
float threshold
uint32_t nms_radius
float k
float sigma
std::vector< Keypoint > extract_peaks(std::span< const float > response, uint32_t w, uint32_t h, float threshold, uint32_t nms_radius)
Extract peaks from a response map via non-maximum suppression.
Definition Harris.cpp:184
std::vector< float > harris_response(std::span< const float > gray, uint32_t w, uint32_t h, float k, float sigma)
Compute the Harris corner response map.
Definition Harris.cpp:19