MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ConnectedComponents.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Features.hpp"
4
5/**
6 * @file ConnectedComponents.hpp
7 * @brief Connected component labelling on normalised float masks.
8 *
9 * Pure functions. No MayaFlux type dependencies.
10 *
11 * ## Conventions
12 * - Input masks are single-channel float where >= 0.5f is foreground
13 * - Label 0 is background; component labels start at 1
14 * - BoundingBox coordinates are normalised to [0, 1]
15 * - 8-connectivity is used throughout
16 */
17
19
20/**
21 * @brief Result of connected component labelling.
22 */
24 std::vector<uint32_t> label_map; ///< Per-pixel label, same size as input mask.
25 std::vector<BoundingBox> boxes; ///< One BoundingBox per component, label 1..count.
26 uint32_t count; ///< Number of components found.
27 bool truncated { false };
28};
29
30/**
31 * @brief Label connected foreground components in a binary mask.
32 *
33 * Uses a two-pass union-find algorithm. First pass assigns provisional
34 * labels and records equivalences. Second pass resolves equivalences and
35 * relabels to a compact 1..count range.
36 *
37 * BoundingBox per component is computed during the second pass.
38 * Coordinates are normalised by w and h to [0, 1].
39 *
40 * @param mask Single-channel float span, size must be w * h.
41 * @param w Image width in pixels.
42 * @param h Image height in pixels.
43 * @return ComponentResult with label_map, boxes, and count.
44 */
45[[nodiscard]] MAYAFLUX_API ComponentResult connected_components(
46 std::span<const float> mask, uint32_t w, uint32_t h);
47
48} // namespace MayaFlux::Kinesis::Vision
uint32_t h
Definition InkPress.cpp:28
ComponentResult connected_components(std::span< const float > mask, uint32_t w, uint32_t h)
Label connected foreground components in a binary mask.
std::vector< uint32_t > label_map
Per-pixel label, same size as input mask.
std::vector< BoundingBox > boxes
One BoundingBox per component, label 1..count.
uint32_t count
Number of components found.
Result of connected component labelling.