digitopo.interop
¶
Conversions between the conventions of digitopo and those of scikit-image.
digitopo keeps the conventions of pink26, which are not those of scikit-image and SciPy on two points:
- connectivity: digitopo names a connectivity by its number of
neighbours (4 or 8 in 2D, 6, 18 or 26 in 3D, 8 or 80 in 4D) and always
asks for it; scikit-image and
scipy.ndimage.generate_binary_structurename it by the largest number of coordinates in which a neighbour differs, from 1 tondim.connectivityandskimage_connectivityconvert one into the other. - grey levels: the grey-level functions of digitopo take
uint8images, while scikit-image works on floats in [0, 1].as_uint8converts an image explicitly; the grey-level functions call it when they are givenconvert=True.
These functions are additions of digitopo; they have no equivalent in pink26.
connectivity
¶
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 |
required |
Returns:
| Type | Description |
|---|---|
int
|
The number of neighbours of a point. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
Examples:
skimage_connectivity
¶
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 |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
Examples:
as_uint8
¶
Return a grey-level image as uint8, for the grey-level functions.
The conversion depends on the dtype, and refuses the values that it could only clip:
uint8: unchanged (no copy when the array is C-contiguous);bool:Falsebecomes 0 andTrue255;- other integers: the values are grey levels, kept as they are; they must lie between 0 and 255;
- floats: the convention of scikit-image, an intensity between 0 and 1
(
skimage.util.img_as_float);vbecomesrint(255 * v), as withskimage.util.img_as_ubyte. NaN and values outside [0, 1] are refused: rescale them first, for example withskimage.exposure.rescale_intensity(image, out_range=(0.0, 1.0)).
The 256 levels merge close values: a smooth gradient may get plateaus, where the place of a crest line depends on the order in which digitopo visits the points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
array_like
|
Array of any shape, of dtype |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
C-contiguous |
Raises:
| Type | Description |
|---|---|
TypeError
|
For another dtype (complex, object...). |
ValueError
|
For integers outside 0..255, or floats outside [0, 1] or NaN. |
Examples: