bacteria_density.utils module
- bacteria_density.utils.bbox_to_polygon(bbox)[source]
Converts a 2D bounding box to a Napari polygon.
- 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).