acia.utils#
Global utilities
- acia.utils.mask_to_polygons(mask)[source]#
Convert a mask to a Polygon or Multipolygon
- Parameters:
mask (np.ndarray) – Binary mask for an object
- Returns:
shapely.geometry.Polygon | shapely.geometry.MultiPolygon | None – Extracted polygon structure, or None if the mask is empty
- Return type:
Polygon | MultiPolygon | None
- acia.utils.largest_polygon(polygon)[source]#
Reduce a possibly-multi-part polygon to its single largest-area part.
mask_to_polygons()returns aMultiPolygonwhenever an object’s mask has disconnected components – a cell the segmentation split in two, a stray speck sharing the cell’s label, or a self-intersecting outline thatbuffer(0)repaired into several pieces. Anything that needs one closed outline (a contour’s coordinates, a drawn shape) has to pick a part, and the largest is the one that represents the object.Note that this discards the smaller parts, so a caller that persists or measures the result is losing whatever area they held; callers in a position to say so should report it.
areais unaffected, being computed from the mask rather than the polygon.- Parameters:
polygon (Polygon | MultiPolygon | None) – A
Polygon, aMultiPolygon, orNone.- Returns:
shapely.geometry.Polygon | None –
- The largest constituent polygon,
polygonitself when it is already a singlePolygon, orNonewhenpolygonisNoneor holds no parts.
- Return type:
Polygon | None