dacapo.utils.affinities

Attributes

logger

Functions

seg_to_affgraph(→ numpy.ndarray)

Constructs an affinity graph from a segmentation.

padding(neighborhood, voxel_size)

Get the appropriate padding to make sure all provided affinities are "True"

Module Contents

dacapo.utils.affinities.logger
dacapo.utils.affinities.seg_to_affgraph(seg: numpy.ndarray, neighborhood: List[funlib.geometry.Coordinate]) numpy.ndarray

Constructs an affinity graph from a segmentation.

Parameters:
  • seg (np.ndarray) – The segmentation array.

  • neighborhood (List[Coordinate]) – The list of coordinates representing the neighborhood.

Returns:

The affinity graph.

Return type:

np.ndarray

Raises:

RuntimeError – If the number of dimensions is not 2 or 3.

Examples

>>> seg = np.array([[1, 1, 2], [1, 1, 2], [3, 3, 4]])
>>> neighborhood = [Coordinate(1, 0), Coordinate(0, 1)]
>>> seg_to_affgraph(seg, neighborhood)
array([[[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[1, 1, 0],
        [1, 1, 0],
        [0, 0, 0]]], dtype=int32)

Notes

The affinity graph is represented as: shape = (e, z, y, x) nhood.shape = (edges, 3)

dacapo.utils.affinities.padding(neighborhood, voxel_size)

Get the appropriate padding to make sure all provided affinities are “True”

Parameters:
  • neighborhood (List[Coordinate]) – The list of coordinates representing the neighborhood.

  • voxel_size (Coordinate) – The voxel size.

Returns:

The negative and positive padding.

Return type:

Tuple[Coordinate, Coordinate]

Raises:

RuntimeError – If the number of dimensions is not 2 or 3.

Examples

>>> neighborhood = [Coordinate(1, 0), Coordinate(0, 1)]
>>> voxel_size = Coordinate(1, 1)
>>> padding(neighborhood, voxel_size)
(Coordinate(0, 0), Coordinate(1, 1))