acia.segm.utils#
Utils for segmentation data handling
- acia.segm.utils.compute_indices(frame, size_t, size_z)[source]#
Compute t and z values from a linearized frame number
- acia.segm.utils.length_and_area(contour)[source]#
Compute length and area of a contour object (in pixel coordinates)
- acia.segm.utils.merge_cells_to_colonies(overlay, expand=10)[source]#
Computing colony blobs from single-cell overlay
- acia.segm.utils.extract_segmentation_stacks(source, overlay, margin=10, frame=0)[source]#
Extract individual image stacks for each segmentation in an overlay.
For each contour/instance in the overlay (optionally filtered by frame), extracts a cropped image stack centered on the segmentation’s bounding box with an optional margin. Uses toMask() to compute bounding boxes. The bounding boxes are clipped to image bounds (no padding is applied).
- Parameters:
source (THWCSequenceSource) – The source image stack with shape [T, H, W, C].
overlay (Overlay) – Overlay containing Contour or Instance objects.
margin (int) – Margin in pixels to add around each bounding box. Defaults to 10.
frame (int | None) – If specified, only extract segmentations from this frame. If None, extract all segmentations regardless of frame. Defaults to 0.
- Returns:
Dictionary mapping contour/instance IDs to their corresponding cropped image stacks. Each cropped stack maintains the full time dimension but has reduced H and W dimensions.
- Raises:
ValueError – If margin is negative.
- Return type:
Example
>>> source = THWCSequenceSource(np.zeros((10, 100, 100, 3))) >>> contours = [Contour([[10, 10], [20, 10], [20, 30], [10, 30]], -1, 0, id=1)] >>> overlay = Overlay(contours) >>> stacks = extract_segmentation_stacks(source, overlay, margin=5, frame=0) >>> stacks[1].image_stack.shape (10, 25, 15, 3)