210 {
211 std::vector<uint8_t> mask;
212 const std::array<int, 4> xywh = n->create_binary_image(mask);
213 const int w = xywh[2];
214 const int h = xywh[3];
215 if (w <= 0 || h <= 0)
216 return 0.0f;
217
218
219
220 const int pw = w + 2;
221 const int ph = h + 2;
222 constexpr float INF = 1e20f;
223
224 std::vector<float> grid(static_cast<size_t>(pw) * ph);
225 for (int y = 0; y < ph; ++y) {
226 for (int x = 0; x < pw; ++x) {
227 const bool inside = x >= 1 && x <= w && y >= 1 && y <= h &&
228 mask[static_cast<size_t>(y - 1) * w + (x - 1)];
229 grid[static_cast<size_t>(y) * pw + x] = inside ? INF : 0.0f;
230 }
231 }
232
233
234 std::vector<float> in, out(std::max(pw, ph));
235 in.resize(ph);
236 for (int x = 0; x < pw; ++x) {
237 for (int y = 0; y < ph; ++y)
238 in[y] = grid[static_cast<size_t>(y) * pw + x];
239 dt_1d(in, out, ph);
240 for (int y = 0; y < ph; ++y)
241 grid[static_cast<size_t>(y) * pw + x] = out[y];
242 }
243 in.resize(pw);
244 float max_d2 = 0.0f;
245 for (int y = 0; y < ph; ++y) {
246 for (int x = 0; x < pw; ++x)
247 in[x] = grid[static_cast<size_t>(y) * pw + x];
248 dt_1d(in, out, pw);
249 for (int x = 0; x < pw; ++x)
250 if (out[x] > max_d2)
251 max_d2 = out[x];
252 }
253 return std::sqrt(max_d2);
254}