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

◆ extract_peaks()

MAYAFLUX_API std::vector< Keypoint > MayaFlux::Kinesis::Vision::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.

A pixel is a peak if its response exceeds threshold and it is the strict maximum within a square window of half-size nms_radius. Ties are broken in favour of the pixel with the lower raster index.

Returned Keypoints are sorted by descending response.

Parameters
responseResponse map span, size must be w * h, values in [0, 1].
wImage width in pixels.
hImage height in pixels.
thresholdMinimum response value to consider. In [0, 1].
nms_radiusNon-maximum suppression half-window size in pixels.
Returns
Keypoints sorted by descending response.

Definition at line 197 of file Harris.cpp.

200{
201 const auto n = static_cast<size_t>(w) * h;
202 const auto r = static_cast<int32_t>(nms_radius);
203
204 std::vector<Keypoint> keypoints;
205
206 for (uint32_t py = 0; py < h; ++py) {
207 for (uint32_t px = 0; px < w; ++px) {
208 const size_t idx = static_cast<size_t>(py) * w + px;
209 const float val = response[idx];
210
211 if (val < threshold)
212 continue;
213
214 bool is_max = true;
215 for (int32_t dy = -r; dy <= r && is_max; ++dy) {
216 const int32_t ny = static_cast<int32_t>(py) + dy;
217 if (ny < 0 || ny >= static_cast<int32_t>(h))
218 continue;
219 for (int32_t dx = -r; dx <= r && is_max; ++dx) {
220 if (dx == 0 && dy == 0)
221 continue;
222 const int32_t nx = static_cast<int32_t>(px) + dx;
223 if (nx < 0 || nx >= static_cast<int32_t>(w))
224 continue;
225 const size_t ni = static_cast<size_t>(ny) * w + nx;
226 if (response[ni] >= val)
227 is_max = false;
228 }
229 }
230
231 if (!is_max)
232 continue;
233
234 keypoints.push_back({
235 .position = {
236 (static_cast<float>(px) + 0.5F) / static_cast<float>(w),
237 (static_cast<float>(py) + 0.5F) / static_cast<float>(h) },
238 .response = val,
239 .scale = 1.0F,
240 .angle = 0.0F,
241 });
242 }
243 }
244
245 std::ranges::sort(keypoints, [](const Keypoint& a, const Keypoint& b) {
246 return a.response > b.response;
247 });
248
249 return keypoints;
250}
uint32_t h
Definition InkPress.cpp:29
size_t a
size_t b
uint32_t py
uint32_t px
float threshold

References a, b, h, px, py, and threshold.

Referenced by MayaFlux::Yantra::FeatureExtractor< InputType, OutputType >::extract_implementation(), and MayaFlux::Kinesis::Vision::VisionExecutor::run().

+ Here is the caller graph for this function: