MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ harris_response() [2/2]

MAYAFLUX_API std::vector< float > MayaFlux::Kinesis::Vision::harris_response ( std::span< const float >  gray,
uint32_t  w,
uint32_t  h,
float  k = 0.04F,
float  sigma = 1.0F 
)

Compute the Harris corner response map.

For each pixel computes R = det(M) - k * trace(M)^2 where M is the structure tensor accumulated over a sigma-weighted window. Negative responses are clamped to 0. Output is normalised to [0, 1] by the observed peak response.

Structure tensor gradients are computed via a 3x3 Sobel operator. The tensor is smoothed with a Gaussian of standard deviation sigma before computing det and trace.

Parameters
graySingle-channel float span, size must be w * h.
wImage width in pixels.
hImage height in pixels.
kHarris sensitivity parameter. Typical range [0.04, 0.06].
sigmaGaussian smoothing sigma for structure tensor. Must be > 0.
Returns
Response map float vector of length w * h, values in [0, 1].

Definition at line 36 of file Harris.cpp.

39{
40 const size_t n = static_cast<size_t>(w) * h;
41
42 auto grad = sobel(gray, w, h);
43
44 std::vector<float> ixx(n), iyy(n), ixy(n);
45
46 std::for_each(std::execution::par_unseq,
47 std::views::iota(size_t { 0 }, n).begin(),
48 std::views::iota(size_t { 0 }, n).end(),
49 [&](size_t i) {
50 const float dx = grad.dx[i];
51 const float dy = grad.dy[i];
52 ixx[i] = dx * dx;
53 iyy[i] = dy * dy;
54 ixy[i] = dx * dy;
55 });
56
57 auto sxx = gaussian_blur(ixx, w, h, sigma);
58 auto syy = gaussian_blur(iyy, w, h, sigma);
59 auto sxy = gaussian_blur(ixy, w, h, sigma);
60
61 std::vector<float> response(n);
62
63 std::for_each(std::execution::par_unseq,
64 std::views::iota(size_t { 0 }, n).begin(),
65 std::views::iota(size_t { 0 }, n).end(),
66 [&](size_t i) {
67 const float det = sxx[i] * syy[i] - sxy[i] * sxy[i];
68 const float trace = sxx[i] + syy[i];
69 response[i] = std::max(0.0F, det - k * trace * trace);
70 });
71
72 normalize_response(response);
73
74 return response;
75}
uint32_t h
Definition InkPress.cpp:29
void sobel(std::span< const float > gray, std::span< float > dx, std::span< float > dy, std::span< float > tmp, uint32_t w, uint32_t h)
Sobel gradient writing dx and dy into caller-supplied buffers.
Definition Gradient.cpp:64

References gaussian_blur(), h, and sobel().

Referenced by MayaFlux::Kinesis::Vision::VisionExecutor::run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: