bacteria_density.utils module

bacteria_density.utils.as_polygon(coordinates)[source]
bacteria_density.utils.avg_in_bins(bin_indices, values)[source]
bacteria_density.utils.bbox_to_polygon(bbox)[source]

Converts a 2D bounding box to a Napari polygon.

bacteria_density.utils.bbox_to_str(bbox)[source]
bacteria_density.utils.clr_to_str(clr)[source]
bacteria_density.utils.from_polygon(polygon)[source]
bacteria_density.utils.get_binned_distances(bin_length, distances)[source]
bacteria_density.utils.make_crop(image, shape, bbox)[source]

Crop a (N,…,H,W) image stack to the polygon shape, safely clamped to the image bounds and optionally intersected with bbox.

Parameters:
  • image – array-like where last two dims are (H, W) (e.g. (Z, H, W) or (C, H, W))

  • shape – a shapely Polygon in the same pixel coordinate space as the image

  • bbox – optional tuple (ymin, xmin, ymax, xmax) to further intersect the crop

Returns:

The cropped stack as an array with the same leading dims as image and spatial dims reduced to the intersection (may be empty if no overlap).

bacteria_density.utils.polygon_to_bbox(polygon)[source]

Converts a Napari polygon to a 2D bounding box.

bacteria_density.utils.polygon_to_mask(poly, shape)[source]
bacteria_density.utils.random_id()[source]
bacteria_density.utils.reset_folder(path)[source]
bacteria_density.utils.str_to_clr(clr_str)[source]
bacteria_density.utils.sum_in_bins(bin_indices, values)[source]