Skip to content

API reference

The reference pages are generated from the docstrings of the modules (numpydoc style). Each page lists the members of the module's __all__.

Module Content
digitopo.topology Topological numbers, simple points, point types and classes, end, curve and junction points, Euler characteristic, topology
digitopo.skeleton Sequential and parallel homotopic skeletons, classic 2D thinnings
digitopo.watershed Topological watershed, watershed lines from markers, labelled basins as in scikit-image
digitopo.grayscale Homotopic thinning, thickening, kernel and lambda-kernel of grey-level images
digitopo.distance Distance maps (7 kinds)
digitopo.io Reading and writing Pink PGM files
digitopo.evaluation Topological evaluation of a segmentation: topology errors, clDice
digitopo.measure Branches of a skeleton, their lengths, pruning of spurs
digitopo.interop Conventions of scikit-image: connectivity, conversion to uint8

Conventions shared by all the modules (see Design of the API):

  • any array_like is accepted; every nonzero value is an object point;
  • 2D arrays are (rows, columns), 3D arrays (depth, rows, columns);
  • the outside of the array is background (except for the watershed and the grey-level operators, see their pages);
  • connectivity has no default (see digitopo with scikit-image for the conversion);
  • for the grey-level operators and the topological watershed, connectivity is that of the minima, that is of the background of a 0/255 image: 4 thins the object as an 8-connected one (see Concepts);
  • no function modifies its input;
  • errors, as in pink26: TypeError for a wrong dtype or a non-integer argument; ValueError for an invalid value (dimension, shape, empty axis, a connectivity that does not exist in the dimension, a value out of range); digitopo.DigitopoError, a subclass of ValueError, for an input that is valid in principle but that digitopo cannot process (connectivity 18 where an operator does not handle it, a variant that Pink does not provide, an image too large for the core, a distance that overflows, a malformed file).

Digital topology operators for binary images, implemented in Rust.

The public API follows pink26 (same modules, functions and parameters), so that code written for one runs with the other:

Arrays are 2D (rows, columns) or 3D (depth, rows, columns) (4D for digitopo.topology.simple_points). Any nonzero value is an object point; the outside of the array is background. The connectivity of the object is mandatory: 4 or 8 in 2D, 6 or 26 in 3D (8 or 80 in 4D); the background uses the complementary one. digitopo.connectivity converts a connectivity of scikit-image (1 to ndim) into this number.

DigitopoError

Bases: ValueError

An input that digitopo cannot process, although it is valid in principle.

The rule of pink26's Pink26Error: connectivity 18 where an operator does not handle it, a variant that Pink does not provide, an image too large for the core, a distance that overflows, a malformed file. An invalid value (a connectivity that does not exist in the dimension, a negative label, a value out of range) raises a plain ValueError. DigitopoError derives from ValueError, so except ValueError catches both.

connectivity

connectivity(ndim: int, skimage_connectivity: int) -> int

Return the digitopo connectivity of a scikit-image connectivity.

scikit-image (connectivity of skimage.measure.label, skimage.segmentation.watershed, skimage.morphology) and SciPy (scipy.ndimage.generate_binary_structure(ndim, connectivity)) count as neighbours the points that differ from the point by at most skimage_connectivity coordinates, each by 1. digitopo gives the number of these neighbours instead.

====== ========================== ====================== ndim scikit-image connectivity digitopo connectivity ====== ========================== ====================== 2 1, 2 4, 8 3 1, 2, 3 6, 18, 26 4 1, 4 8, 80 ====== ========================== ======================

The result is not always accepted by the function it is given to: 18 is accepted only by digitopo.watershed, and 4D only by digitopo.topology.simple_points.

Parameters:

Name Type Description Default
ndim int

Number of dimensions of the image, at least 1.

required
skimage_connectivity int

From 1 to ndim.

required

Returns:

Type Description
int

The number of neighbours of a point.

Raises:

Type Description
TypeError

If ndim or skimage_connectivity is not an integer.

ValueError

If ndim is below 1, or skimage_connectivity is not between 1 and ndim.

Examples:

>>> import digitopo
>>> digitopo.connectivity(2, 1), digitopo.connectivity(2, 2)
(4, 8)
>>> digitopo.connectivity(3, 3)
26

skimage_connectivity

skimage_connectivity(ndim: int, connectivity: int) -> int

Return the scikit-image connectivity of a digitopo connectivity.

The inverse of connectivity: for example, to label the objects whose topology digitopo counts with connectivity=8, call skimage.measure.label(mask, connectivity=skimage_connectivity(2, 8)).

Parameters:

Name Type Description Default
ndim int

Number of dimensions of the image, at least 1 (8 means two different neighbourhoods in 2D and in 4D).

required
connectivity int

A number of neighbours: 4 or 8 in 2D, 6, 18 or 26 in 3D...

required

Returns:

Type Description
int

From 1 to ndim.

Raises:

Type Description
TypeError

If ndim or connectivity is not an integer.

ValueError

If ndim is below 1, or connectivity is not a number of neighbours of the ndim-dimensional grid (4 or 8 in 2D, 6, 18 or 26 in 3D, ...).

Examples:

>>> import digitopo
>>> digitopo.skimage_connectivity(2, 8), digitopo.skimage_connectivity(3, 6)
(2, 1)