// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #pragma once #include #include // 8-connected labelling of a dense boolean map of nx by ny cells, stored row-major. // Returns one label per cell: 0 for a cell that is not set and for a component smaller // than min_size, 1..n for the components that survive. Labels are not renumbered after // the size cut, so the returned labels are not necessarily contiguous. // // Corner-touching cells are one component. On a grid scan that matters: where the step is // coarser than the beam, a needle lying diagonally is sampled as a chain of cells that meet // only at their corners, and 4-connectivity would break it into single cells that every // minimum-size cut then throws away. std::vector LabelConnectedComponents(const std::vector &map, int64_t nx, int64_t ny, int64_t min_size);