Module iaf.morph.watershed

Watershed-based operations.

Functions

def estimate_object_sizes(bw: numpy.ndarray)

Estimate area, min axis length, major axis length and equivalent diameter of all objects in a mask as their median values.

Parameters

bw : numpy array
Black and white mask.

Returns

results : tuple
Tuple containing (area, min_axis, max_axis, equiv_diam) as the median values of the corresponding measurements for all objects.
def filter_labels_by_area(label_image: numpy.ndarray, min_area: int, max_area: Optional[int] = None) ‑> tuple

Remove objects that have areas outside the specified range.

Parameters

label_image : numpy array
Image labeled by scipy.ndimage.label
min_area : int
Minimum allowed area of objects to be preserved.
max_area : int
Maximum allowed area of objects to be preserved. Optional, if omitted only small objects will be filtered.

Returns

results : Tuple
The tuple contains the label image filtered by size, and the updated number of objects.
def get_label_areas(label_image: numpy.ndarray) ‑> tuple

Return a list of label areas from the label image.

Parameters

label_image : numpy array
Image labeled by scipy.ndimage.label

Returns

results : tuple
Tuple with a list of label areas (as a NumPy array), the median area, and the median absolute deviation of areas.
def label_to_eroded_bw_mask(nuclei_labels: numpy.ndarray, sel:  = array([[1., 1., 1.], [1., 1., 1.], [1., 1., 1.]]))

Create a black-and-white mask from a label image. To keep the label separate in the back-and-white mask, they are individually eroded.

Parameters

nuclei_labels : np.ndarray
Label image.
sel : np.ndarray
Structuring element for erosion.

Returns

bw : np.ndarray
Black-and-white mask.
def separate_neighboring_objects(bw_image: numpy.ndarray, label_image: numpy.ndarray, filter_size: Optional[int] = None, maxima_suppression_size: Optional[int] = None, unclump_method: Optional[str] = 'shape', watershed_method: Optional[str] = 'shape', fill_holes: str = 'both', min_size: int = 20, max_size: int = 100, low_res_maxima: bool = True, exclude_border_objects: bool = False) ‑> tuple

Separate objects based on intensity or distance transform.

This is extracted, simplified and adapted from CellProfiler's IdentifyPrimaryObjects module and uses a modified version of centrosome.

See: IdentifyPrimaryObjects's source code

Parameters

bw_image : numpy array
Black-and-white binary mask.
label_image : numpy array
Image labeled by scipy.ndimage.label
filter_size : int | None
Filter size for image blurring (optional, default = None). If None, it will be calculated from range_min.
maxima_suppression_size : int | None
Size of mask for maximum suppression (optional, default = None) If None, it will be estimated automatically.
unclump_method : str | None
Method to unclump the objects. One of: { "intensity", "shape" } (Optional, default = "shape")
watershed_method : str | None
Method to unclump the objects. One of: { "intensity", "shape", "propagate" } (Optional, default = "intensity")
fill_holes : str
Whether and when to fill holes in the black-and-white mask. One of "never": holes are never filled "both": before and after declumping "after": after declumping only (Optional, default = "never")
min_size : int
Minimum expected diameter of objects. (Optional, default = 20)
max_size : int
Maximum expected diameter of objects. (Optional, default = 100)
low_res_maxima : boolean
Whether to down-sample the image for declumping. Will be ignored if range_min is < 10. (Optional, default = False)
exclude_border_objects : boolean
Whether to exclude objects touching the borders of the image (optional, default = False)

Returns

results : tuple
Tuple with (label image: numpy array, object_count: int, max_suppression_size: float)