scipy.ndimage.distance_transform_bf¶
-
scipy.ndimage.
distance_transform_bf
(input, metric='euclidean', sampling=None, return_distances=True, return_indices=False, distances=None, indices=None)[source]¶ Distance transform function by a brute force algorithm.
This function calculates the distance transform of the input, by replacing each foreground (non-zero) element, with its shortest distance to the background (any zero-valued element).
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{‘euclidean’, ‘taxicab’, ‘chessboard’}, optional
‘cityblock’ and ‘manhattan’ are also valid, and map to ‘taxicab’. The default is ‘euclidean’.
- samplingfloat, or sequence of float, optional
This parameter is only used when metric is ‘euclidean’. Spacing of elements along each dimension. If a sequence, must be of length equal to the input rank; if a single number, this is used for all axes. If not specified, a grid spacing of unity is implied.
- return_distancesbool, optional
Whether to calculate the distance transform. Default is True.
- return_indicesbool, optional
Whether to calculate the feature transform. Default is False.
- distancesndarray, 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, and of type float64 if metric is ‘euclidean’, uint32 otherwise.
- 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
- distancesndarray, 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.
Notes
This function employs a slow brute force algorithm, see also the function distance_transform_cdt for more efficient taxicab and chessboard algorithms.