scipy.ndimage.distance_transform_cdt¶
-
scipy.ndimage.
distance_transform_cdt
(input, metric='chessboard', return_distances=True, return_indices=False, distances=None, indices=None)[source]¶ Distance transform for chamfer type of transforms.
In addition to the distance transform, the feature transform can be calculated. In this case the index of the closest background element to each foreground element is returned in a separate array.
- Parameters
- inputarray_like
Input
- metric{‘chessboard’, ‘taxicab’} or array_like, optional
The metric determines the type of chamfering that is done. If the metric is equal to ‘taxicab’ a structure is generated using generate_binary_structure with a squared distance equal to 1. If the metric is equal to ‘chessboard’, a metric is generated using generate_binary_structure with a squared distance equal to the dimensionality of the array. These choices correspond to the common interpretations of the ‘taxicab’ and the ‘chessboard’ distance metrics in two dimensions. A custom metric may be provided, in the form of a matrix where each dimension has a length of three. ‘cityblock’ and ‘manhattan’ are also valid, and map to ‘taxicab’. The default is ‘chessboard’.
- return_distancesbool, optional
Whether to calculate the distance transform. Default is True.
- return_indicesbool, optional
Whether to calculate the feature transform. Default is False.
- distancesint32 ndarray, optional
An output array to store the calculated distance transform, instead of returning it. This parameter is only used when return_distances is True. It must be the same shape as input.
- indicesint32 ndarray, optional
An output array to store the calculated feature transform, instead of returning it. Its shape must be (input.ndim,) + input.shape.
- Returns
- distancesint32 ndarray, optional
The calculated distance transform. Returned only when return_distances is True, and distances is not supplied. It will have the same shape as the input array.
- indicesint32 ndarray, optional
The calculated feature transform. It has an input-shaped array for each dimension of the input. See distance_transform_edt documentation for an example. Returned only when return_indices is True, and indices is not supplied.