iaf.morph.morphology_utils¶
Functions
|
Shrink a binary image to its topological skeleton/medial points. |
|
Fill background pixels that are enclosed holes inside foreground objects. |
|
Return a boolean mask of pixels that are local maxima within their label. |
|
Re-number labels in image to be consecutive starting from 1. |
|
Return a filled-disk boolean structuring element of the given radius. |
- iaf.morph.morphology_utils.binary_shrink(image: ndarray, iterations: int = -1) ndarray[source]¶
Shrink a binary image to its topological skeleton/medial points.
We use
skimage.morphology.skeletonize, which produces the same topological skeleton (as Centrosome’sbinary_shrink) via the Zhang-Suen thinning algorithm. The output is guaranteed to contain at least one point per connected component of the input.- Parameters:
image – Binary (bool or uint8) 2-D array.
iterations – Kept for API compatibility; ignored (skeletonize runs to convergence).
- Return type:
- iaf.morph.morphology_utils.fill_labeled_holes(labels: ndarray, mask: ndarray | None = None, size_fn=None) ndarray[source]¶
Fill background pixels that are enclosed holes inside foreground objects.
This is a pure numpy port of centrosome’s
fill_labeled_holes+ its compiledfill_labeled_holes_loophelper. It builds a graph whose nodes are the foreground objects (ids1 ... lcount) and the connected components of background (idslcount+1 ... lmax), then runs the same two-phase worklist algorithm centrosome uses.- Parameters:
labels – Label image (0 = background, >0 = object label). Also accepts a binary image — the return dtype matches the input dtype.
mask – Optional boolean mask; pixels outside the mask are excluded from the background search.
size_fn – Optional callable
(size: int, is_foreground: bool) -> bool. ReturningFalsefor a region immediately marks it “not a hole” (vetoing it from ever being filled).
- Returns:
Copy of labels with holes replaced by the label of the enclosing object, same dtype as input.
- Return type:
- iaf.morph.morphology_utils.is_local_maximum(image: ndarray, labels: ndarray, footprint: ndarray) ndarray[source]¶
Return a boolean mask of pixels that are local maxima within their label.
A foreground pixel is a local maximum if, for every neighbouring pixel within footprint that shares the same label, the neighbour’s value does not exceed the centre pixel’s value. Neighbours that belong to a different label (including background) never disqualify a candidate.
- Parameters:
image – Intensity (or distance-transform) image.
labels – Integer label image (0 = background).
footprint – Boolean structuring element defining the neighbourhood. Must have odd dimensions; the centre cell is ignored.
- Return type:
- iaf.morph.morphology_utils.relabel(image: ndarray) tuple[ndarray, int][source]¶
Re-number labels in image to be consecutive starting from 1.
- Parameters:
image – Integer label image (background == 0).
- Return type:
(relabeled_image, object_count)
- iaf.morph.morphology_utils.strel_disk(radius: float) ndarray[source]¶
Return a filled-disk boolean structuring element of the given radius.
Exact port of centrosome’s
strel_disk: every pixel whose centre lies within radius of the origin is set to 1.- Parameters:
radius – Radius of the disk (float; sub-pixel precision is respected).
- Returns:
1 inside the disk, 0 outside.
- Return type:
numpy.ndarray of float32, shape
(2*iradius+1, 2*iradius+1)