API Reference

mwatershed.agglom(affinities, offsets, seeds=None, edges=None, strides=None, randomized_strides=False)

Perform affinity-based agglomeration using mutex watershed. Given affinities and their associated offsets, this function will return a label array containing a segmentation of the input affinities array.

Parameters:
  • affinities (ndarray) – Affinities to be segmented. Boundaries between objects should be negative, and affinities within objects should be positive. Mutex is a greedy algorithm that will always process edges in descending order of magnitude.

  • offsets (Sequence[Sequence[int]]) – List of offsets to be used for the affinities. Each offset should be a list of integers, representing the offset per dimension. For example for 3D affinities, offsets are typically something like: [[1, 0, 0], [0, 1, 0], [0, 0, 1], [2, 0, 0], [0, 2, 0], [0, 0, 2]].

  • seeds (Optional[ndarray]) – Optional seed array. If provided, any non-zero values in the seed array are guaranteed to stay unchanged in the output label array. This is useful for preserving certain ids in the output label array. The seed array should be the same shape as the affinities array.

  • edges (Optional[Sequence[tuple[bool, int, int]]]) – Optional list of edges used to guarantee specific merge or split pixels.

  • strides (Optional[Sequence[Sequence[int]]]) – Optional strides to be used for the affinities. Each stride should be a list of integers, representing the stride per dimension. For example for 3D affinities, strides are typically something like: [[1, 1, 1], [1, 1, 1], [1, 1, 1], [2, 1, 1], [1, 2, 1], [1, 1, 2]]. Long range edges are usually split biased, and providing a stride lets us avoid excessive splitting.

  • randomized_strides (bool) – If True, the strides will be randomized by just turning the stride into a probability of selecting a specific affinity via 1/prod(stride).

Return type:

ndarray

mwatershed.cluster_edges(edges)

Perform affinity-based agglomeration using mutex watershed on a set of edges.

Parameters:

edges (Sequence[tuple[float, int, int]]) – List of edges to be used for the affinities. Each edge should be a tuple of (weight, node1, node2). The weight is the affinity between the two nodes. The nodes are the integer ids of the fragments in the graph.

Return type:

list[tuple[int, int]]

Returns:

List of tuples (fragment_id: int, segment_id: int) mapping fragments to segments.