Skip to main content

Module distance

Module distance 

Source
Expand description

Distance transforms: for every foreground pixel, the distance to the nearest background pixel.

The exact Euclidean transform uses the separable algorithm of Felzenszwalb and Huttenlocher (2004): the squared distance in two dimensions is a one-dimensional problem along the rows of a one-dimensional answer along the columns, and each one-dimensional problem is the lower envelope of parabolas, found in linear time. The chamfer transforms (city-block and chessboard) need only two raster sweeps.

See the book entry Morphology, distance transforms and labelling.

Structs§

DistanceTransform
The exact Euclidean distance transform with its feature transform.

Enums§

ChamferMetric
The metric of a chamfer distance transform.

Functions§

distance_transform_cdt
The chamfer distance transform (SciPy’s distance_transform_cdt), in integer steps: a forward raster sweep takes each pixel’s distance from its already visited neighbours (up and left), and a backward sweep from the others. Background pixels get 0. Images without background give None for every pixel.
distance_transform_edt
The exact Euclidean distance transform of a binary image (SciPy’s distance_transform_edt): for each foreground (true) pixel, the distance to the nearest background (false) pixel, with pixel spacing sampling = (row spacing, column spacing) (default (1, 1)). Background pixels get 0. The image must contain at least one background pixel.