digitopo.topology
¶
Digital topology of binary images: topological numbers, simple points, point classes.
The functions, parameters, return types and codes are those of
pink26.topology; euler_characteristic and topology are
additions.
For a point p, T(p) counts the pieces of the object around p that touch
p, and T̄(p) the same for the background with the complementary
connectivity. Around p means the 8 pixels in 2D, the 26 voxels for a
26-connected 3D object and the 18 face or edge voxels for a 6-connected one
(Bertrand's geodesic neighbourhood); the background of a 26-connected object
is 6-connected and uses the 18 voxels, that of a 6-connected object uses the
26. An object point is simple when T = 1 and T̄ = 1.
Simplicity is tested with Theorem 15 of Couprie and Bertrand (2009), on the cubical complex of the pixels; for 4 and 6 connectivity by duality. The two characterizations agree on all 2D and 3D configurations (tests of the crate).
References
G. Bertrand, "Simple points, topological numbers and geodesic neighborhoods in cubic grids", Pattern Recognition Letters 15(10), 1994, pp. 1003-1011.
M. Couprie, G. Bertrand, "New characterizations of simple points in 2D, 3D, and 4D discrete spaces", IEEE TPAMI 31(4), 2009, pp. 637-648.
G. Malandain, G. Bertrand, N. Ayache, "Topological segmentation of discrete surfaces", International Journal of Computer Vision 10(2), 1993, pp. 183-197.
PointType
¶
Bases: IntEnum
Type of a point, as returned by point_types (codes of pink26).
BACKGROUND (0) not in the object; SIMPLE (1) T = 1 and T̄ = 1;
MULTIPLE (2) T > 2; SEPARATING (3) T = 2; ISOLATED (4) T = 0;
INTERIOR (5) T̄ = 0; OTHER (6) any other object point, for example a
voxel of a surface one voxel thick (T = 1, T̄ = 2). The rules are
applied in this order.
PointClass3D
¶
Bases: IntEnum
Class of a 3D point of a 26-connected object (codes of pink26).
Types A to I of Malandain, Bertrand and Ayache (1993), Table 1, in this
order: INTERIOR T̄ = 0; ISOLATED T = 0; BORDER T̄ = 1, T = 1;
CURVE T̄ = 1, T = 2; CURVES_JUNCTION T̄ = 1, T > 2; SURFACE
T̄ = 2, T = 1; SURFACE_CURVE_JUNCTION T̄ = 2, T ≥ 2;
SURFACES_JUNCTION T̄ > 2, T = 1; SURFACES_CURVES_JUNCTION
T̄ > 2, T ≥ 2.
Topology
¶
Bases: NamedTuple
Topology of a binary image, as returned by topology.
holes counts the holes of a 2D object and the tunnels of a 3D one
(first Betti number); cavities is 0 in 2D. euler is
objects - holes + cavities.
topological_numbers
¶
topological_numbers(
image: ArrayLike, connectivity: int
) -> tuple[NDArray[np.uint8], NDArray[np.uint8]]
Compute the topological numbers T and T̄ of every point, object or background.
T counts the pieces of the object around the point that touch it, T̄ the same for the background (see the module documentation).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
array_like
|
2D array |
required |
connectivity
|
int
|
Connectivity of the object: 4 or 8 in 2D, 6 or 26 in 3D. No default (the choice changes the result); 18 is refused. The background uses the other one. |
required |
Returns:
| Type | Description |
|---|---|
t, t_bar : tuple of numpy.ndarray
|
Two new |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
DigitopoError
|
If |
Examples:
>>> import numpy as np, digitopo
>>> square = np.zeros((5, 5), dtype=bool)
>>> square[1:4, 1:4] = True
>>> t, t_bar = digitopo.topology.topological_numbers(square, 8)
>>> int(t[2, 2]), int(t_bar[2, 2]) # the centre: no background around it
(1, 0)
>>> int(t[1, 1]), int(t_bar[1, 1]) # a corner: one piece of each
(1, 1)
simple_points
¶
Find the simple points: object points whose removal keeps the topology.
A point is simple when T = 1 and T̄ = 1. Background points are
never simple.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
array_like
|
2D, 3D or 4D array of |
required |
connectivity
|
int
|
Connectivity of the object: 4 or 8 in 2D, 6 or 26 in 3D, 8 or 80 in 4D. No default; 18 is refused. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
New |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
DigitopoError
|
If |
Examples:
point_types
¶
Classify every point with the codes of PointType.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
array_like
|
2D array |
required |
connectivity
|
int
|
Connectivity of the object: 4 or 8 in 2D, 6 or 26 in 3D. No default (the choice changes the result); 18 is refused. The background uses the other one. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
New |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
DigitopoError
|
If |
Examples:
point_classes_3d
¶
Classify every point of a 3D image with the codes of PointClass3D.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
array_like
|
3D array |
required |
connectivity
|
int
|
Only 26 is defined. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
New |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
DigitopoError
|
If |
Examples:
end_points
¶
Find the end points: object points with exactly 1 object neighbour.
Meaningful on a thin object such as a skeleton.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
array_like
|
2D array |
required |
connectivity
|
int
|
Connectivity of the object: 4 or 8 in 2D, 6 or 26 in 3D. No default (the choice changes the result); 18 is refused. The background uses the other one. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
New |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
DigitopoError
|
If |
Examples:
curve_points
¶
Find the curve points: T = 2 and exactly 2 object neighbours.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
array_like
|
2D array |
required |
connectivity
|
int
|
Connectivity of the object: 4 or 8 in 2D, 6 or 26 in 3D. No default (the choice changes the result); 18 is refused. The background uses the other one. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
New |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
DigitopoError
|
If |
Examples:
junction_points
¶
Find the junction points: object points with at least 3 object neighbours.
Meaningful on a thin skeleton: on a thick object nearly every point counts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
array_like
|
2D array |
required |
connectivity
|
int
|
Connectivity of the object: 4 or 8 in 2D, 6 or 26 in 3D. No default (the choice changes the result); 18 is refused. The background uses the other one. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
New |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
DigitopoError
|
If |
Examples:
euler_characteristic
¶
Return the Euler characteristic of the object for its connectivity.
2D: objects - holes. 3D: objects - tunnels + cavities. It equals
skimage.measure.euler_number(image, connectivity=1) for connectivity
4 or 6 and connectivity=image.ndim for 8 or 26.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
array_like
|
2D array |
required |
connectivity
|
int
|
Connectivity of the object: 4 or 8 in 2D, 6 or 26 in 3D. No default (the choice changes the result); 18 is refused. The background uses the other one. |
required |
Returns:
| Type | Description |
|---|---|
int
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
DigitopoError
|
If |
Examples:
topology
¶
Count the objects, holes (2D) or tunnels (3D) and cavities of a binary image.
The objects use connectivity, the holes and cavities the
complementary one; the outside of the array is background.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
array_like
|
2D array |
required |
connectivity
|
int
|
Connectivity of the object: 4 or 8 in 2D, 6 or 26 in 3D. No default (the choice changes the result); 18 is refused. The background uses the other one. |
required |
Returns:
| Type | Description |
|---|---|
Topology
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
DigitopoError
|
If |
Examples: