MayaFlux 0.5.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 184 of file Harris.cpp.

187{
188 const auto n = static_cast<size_t>(w) * h;
189 const auto r = static_cast<int32_t>(nms_radius);
190
191 std::vector<Keypoint> keypoints;
192
193 for (uint32_t py = 0; py < h; ++py) {
194 for (uint32_t px = 0; px < w; ++px) {
195 const size_t idx = static_cast<size_t>(py) * w + px;
196 const float val = response[idx];
197
198 if (val < threshold)
199 continue;
200
201 bool is_max = true;
202 for (int32_t dy = -r; dy <= r && is_max; ++dy) {
203 const int32_t ny = static_cast<int32_t>(py) + dy;
204 if (ny < 0 || ny >= static_cast<int32_t>(h))
205 continue;
206 for (int32_t dx = -r; dx <= r && is_max; ++dx) {
207 if (dx == 0 && dy == 0)
208 continue;
209 const int32_t nx = static_cast<int32_t>(px) + dx;
210 if (nx < 0 || nx >= static_cast<int32_t>(w))
211 continue;
212 const size_t ni = static_cast<size_t>(ny) * w + nx;
213 if (response[ni] >= val)
214 is_max = false;
215 }
216 }
217
218 if (!is_max)
219 continue;
220
221 keypoints.push_back({
222 .position = {
223 (static_cast<float>(px) + 0.5F) / static_cast<float>(w),
224 (static_cast<float>(py) + 0.5F) / static_cast<float>(h) },
225 .response = val,
226 .scale = 1.0F,
227 .angle = 0.0F,
228 });
229 }
230 }
231
232 std::ranges::sort(keypoints, [](const Keypoint& a, const Keypoint& b) {
233 return a.response > b.response;
234 });
235
236 return keypoints;
237}
uint32_t h
Definition InkPress.cpp:28
size_t a
size_t b
float threshold
uint32_t nms_radius

References a, b, h, nms_radius, 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: