acia.utils#

Global utilities

acia.utils.lut_mapping(image, in_min, in_max, out_min, out_max, dtype=None)[source]#
acia.utils.pairwise_distances(points)[source]#
Parameters:

points (ndarray)

Return type:

list[float]

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 a MultiPolygon whenever 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 that buffer(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. area is unaffected, being computed from the mask rather than the polygon.

Parameters:

polygon (Polygon | MultiPolygon | None) – A Polygon, a MultiPolygon, or None.

Returns:

shapely.geometry.Polygon | None

The largest constituent polygon,

polygon itself when it is already a single Polygon, or None when polygon is None or holds no parts.

Return type:

Polygon | None

acia.utils.multi_mask_to_polygons(mask)[source]#
Parameters:

mask (ndarray)

Return type:

list[tuple[int, Polygon | MultiPolygon]]

acia.utils.polygon_to_mask(polygon, height, width)[source]#

Converts a polygon to a mask

Parameters:
  • polygon (_type_) – shapely polygon or multipolygon

  • height (int) – height of the mask

  • width (int) – width of the mask

Returns:

(np.ndarray) – boolean mask

class acia.utils.ScaleBar[source]#

Bases: object

Scalebar class

pixelWidth: int#

width of the rendered bar in pixels (set by concrete subclasses)

draw(image, xstart, ystart)[source]#
Parameters: