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

Parameters:
  • frame (int) – the linearized frame index

  • size_t (int) – the total size of the t dimension

  • size_z (int) – the total size of the z dimension

Returns:

(Tuple[int, int]) – tuple of (t,z) indices

Return type:

tuple[int, int]

acia.segm.utils.length_and_area(contour)[source]#

Compute length and area of a contour object (in pixel coordinates)

Parameters:

contour (Contour) – contour object

Returns:

tuple[float, float] – length and area of the contour

Return type:

tuple[float, float]

acia.segm.utils.merge_cells_to_colonies(overlay, expand=10)[source]#

Computing colony blobs from single-cell overlay

Parameters:
  • overlay (Overlay) – Single-cell overlay containing the individual cell objects

  • expand (int, optional) – The number of pixels to expand single-cell objects in order to form blobs. Defaults to 10.

Returns:

Overlay – Overlay of colony blobs

Return type:

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:

dict[Any, THWCSequenceSource]

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)