bundles / skimage latest / skimage / measure / _regionprops_utils / euler_number
function
skimage.measure._regionprops_utils:euler_number
source: /dev/scikit-image/src/skimage/measure/_regionprops_utils.py:285
Signature
def euler_number(image, connectivity = None)Summary
Calculate the Euler characteristic in binary image.
Extended Summary
For 2D objects, the Euler number is the number of objects minus the number of holes. For 3D objects, the Euler number is obtained as the number of objects plus the number of holes, minus the number of tunnels, or loops.
Parameters
image: (M, N[, P]) ndarrayInput image. If image is not binary, all values greater than zero are considered as the object.
connectivity: int, optionalMaximum number of orthogonal hops to consider a pixel/voxel as a neighbor. Accepted values are ranging from 1 to input.ndim. If
None, a full connectivity ofinput.ndimis used. 4 or 8 neighborhoods are defined for 2D images (connectivity 1 and 2, respectively). 6 or 26 neighborhoods are defined for 3D images, (connectivity 1 and 3, respectively). Connectivity 2 is not defined.
Returns
euler_number: intEuler characteristic of the set of all objects in the image.
Notes
The Euler characteristic is an integer number that describes the topology of the set of all objects in the input image. If object is 4-connected, then background is 8-connected, and conversely.
The computation of the Euler characteristic is based on an integral geometry formula in discretized space. In practice, a neighborhood configuration is constructed, and a LUT is applied for each configuration. The coefficients used are the ones of Ohser et al.
It can be useful to compute the Euler characteristic for several connectivities. A large relative difference between results for different connectivities suggests that the image resolution (with respect to the size of objects and holes) is too low.
Examples
import numpy as np import skimage as ski SAMPLE = np.zeros((100,100,100)); SAMPLE[40:60, 40:60, 40:60]=1 ski.measure.euler_number(SAMPLE) # doctest: +ELLIPSIS SAMPLE[45:55,45:55,45:55] = 0; ski.measure.euler_number(SAMPLE) # doctest: +ELLIPSIS SAMPLE = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0], [0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1], [0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1]])✓
ski.measure.euler_number(SAMPLE) ski.measure.euler_number(SAMPLE, connectivity=1)✗
Aliases
skimage.measure.euler_number