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

◆ gaussian_kernel_2d()

const std::vector< float > & MayaFlux::Yantra::VisionGpuExecutor::gaussian_kernel_2d ( uint32_t  radius,
float  sigma 
)
private

2D Gaussian kernel for convolution, cached by (radius, sigma bit pattern).

Sigma is a tuning parameter that rarely changes frame to frame; recomputing exp() over (2*radius+1)^2 taps and reallocating the kernel every call is pure repeated work for an identical result.

Parameters
radiusRadius of the kernel in pixels. Kernel size is (2*radius + 1)^2.
sigmaStandard deviation of the Gaussian.
Returns
Normalized kernel weights as a flat vector in row-major order.

Definition at line 10 of file VisionImageDispatch.cpp.

11{
12 static std::unordered_map<uint64_t, std::vector<float>> cache;
13 const uint64_t key = (static_cast<uint64_t>(std::bit_cast<uint32_t>(sigma)) << 32)
14 | radius;
15 auto it = cache.find(key);
16 if (it != cache.end())
17 return it->second;
18
19 const uint32_t diam = 2 * radius + 1;
20 std::vector<float> k(static_cast<size_t>(diam) * diam);
21 float sum = 0.0F;
22 for (uint32_t y = 0; y < diam; ++y) {
23 for (uint32_t x = 0; x < diam; ++x) {
24 const float fx = static_cast<float>(x) - static_cast<float>(radius);
25 const float fy = static_cast<float>(y) - static_cast<float>(radius);
26 const float v = std::exp(-(fx * fx + fy * fy) / (2.0F * sigma * sigma));
27 k[y * diam + x] = v;
28 sum += v;
29 }
30 }
31 for (auto& v : k)
32 v /= sum;
33
34 return cache.emplace(key, std::move(k)).first->second;
35}
float radius
std::vector< double > sum(std::span< const double > data, size_t n_windows, uint32_t hop_size, uint32_t window_size)
Sum per window.
Definition Analysis.cpp:469

References radius.

Referenced by op_canny(), and op_harris_response().

+ Here is the caller graph for this function: