connected_components_with_stats#
- rlemasklib.RLEMask.connected_components_with_stats(connectivity=4, min_size=1, filter_fn=None)[source][C source]#
Extract connected components and their stats in a single pass.
More efficient than calling connected_components() and connected_component_stats() separately when you need both.
- Parameters:
connectivity (int) – 4 or 8, the connectivity of the components.
min_size (int) – the minimum size of a component to return.
filter_fn (Optional[Callable[[ndarray, ndarray, ndarray], ndarray]]) – an optional filter function that receives three numpy arrays (areas, bboxes, centroids) and returns a boolean array indicating which components to extract.
- Returns:
components is a list of RLEMask objects
stats is a tuple of (areas, bboxes, centroids) numpy arrays, or None if empty. areas is shape (n,), bboxes is shape (n, 4) with columns (x, y, w, h), centroids is shape (n, 2) with columns (x, y).
- Return type:
A tuple of (components, stats) where