MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / non_maximal

Function non_maximal

src/backend/cpu/kernel/fast.hpp:171–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169}
170
171void non_maximal(CParam<float> score, CParam<float> x_in, CParam<float> y_in,
172 Param<float> x_out, Param<float> y_out, Param<float> score_out,
173 unsigned *count, unsigned const total_feat,
174 unsigned const edge) {
175 float const *score_ptr = score.get();
176 float const *x_in_ptr = x_in.get();
177 float const *y_in_ptr = y_in.get();
178
179 af::dim4 score_dims = score.dims();
180
181 for (unsigned k = 0; k < total_feat; k++) {
182 unsigned x = static_cast<unsigned>(round(x_in_ptr[k]));
183 unsigned y = static_cast<unsigned>(round(y_in_ptr[k]));
184
185 float v = score_ptr[y + score_dims[0] * x];
186 float max_v;
187 max_v = std::max(score_ptr[y - 1 + score_dims[0] * (x - 1)],
188 score_ptr[y - 1 + score_dims[0] * x]);
189 max_v = std::max(max_v, score_ptr[y - 1 + score_dims[0] * (x + 1)]);
190 max_v = std::max(max_v, score_ptr[y + score_dims[0] * (x - 1)]);
191 max_v = std::max(max_v, score_ptr[y + score_dims[0] * (x + 1)]);
192 max_v = std::max(max_v, score_ptr[y + 1 + score_dims[0] * (x - 1)]);
193 max_v = std::max(max_v, score_ptr[y + 1 + score_dims[0] * (x)]);
194 max_v = std::max(max_v, score_ptr[y + 1 + score_dims[0] * (x + 1)]);
195
196 if (y >= score_dims[1] - edge - 1 || y <= edge + 1 ||
197 x >= score_dims[0] - edge - 1 || x <= edge + 1)
198 continue;
199
200 // Stores keypoint to feat_out if it's response is maximum compared to
201 // its 8-neighborhood
202 if (v > max_v) {
203 unsigned j = *count;
204 ++*count;
205
206 float *x_out_ptr = x_out.get();
207 float *y_out_ptr = y_out.get();
208 float *score_out_ptr = score_out.get();
209
210 x_out_ptr[j] = static_cast<float>(x);
211 y_out_ptr[j] = static_cast<float>(y);
212 score_out_ptr[j] = static_cast<float>(v);
213 }
214 }
215}
216
217} // namespace kernel
218} // namespace cpu

Callers 1

fastFunction · 0.50

Calls 4

roundFunction · 0.85
maxFunction · 0.50
getMethod · 0.45
dimsMethod · 0.45

Tested by

no test coverage detected