# 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 is returned along the first axis of the result.

Parameters
inputarray_like

Input

metricstr, optional

Three types of distance metric are supported: ‘euclidean’, ‘taxicab’, and ‘chessboard’.

sampling{int, sequence of ints}, optional

This parameter is only used in the case of the euclidean metric distance transform.

The sampling along each axis can be given by the sampling parameter which should be a sequence of length equal to the input rank, or a single number in which the sampling is assumed to be equal along all axes.

return_distancesbool, optional

The return_distances flag can be used to indicate if the distance transform is returned.

The default is True.

return_indicesbool, optional

The return_indices flags can be used to indicate if the feature transform is returned.

The default is False.

distancesfloat64 ndarray, optional

Optional output array to hold distances (if return_distances is True).

indicesint64 ndarray, optional

Optional output array to hold indices (if return_indices is True).

Returns
distancesndarray

Distance array if return_distances is True.

indicesndarray

Indices array if return_indices is True.

Notes

This function employs a slow brute force algorithm, see also the function distance_transform_cdt for more efficient taxicab and chessboard algorithms.

#### Previous topic

scipy.ndimage.black_tophat

#### Next topic

scipy.ndimage.distance_transform_cdt