code: def distance_transform_bf(
      input,
      metric="euclidean",
      sampling=None,
      return_distances=True,
      return_indices=False,
      distances=None,
      indices=None,
  ):
      """
      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
      ----------
      input : array_like
          Input
      metric : {'euclidean', 'taxicab', 'chessboard'}, optional
          'cityblock' and 'manhattan' are also valid, and map to 'taxicab'.
          The default is 'euclidean'.
      sampling : float, 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_distances : bool, optional
          Whether to calculate the distance transform.
          Default is True.
      return_indices : bool, optional
          Whether to calculate the feature transform.
          Default is False.
      distances : ndarray, optional
          An output array to store the calculated distance transform, instead of
          returning it.
          `return_distances` must be True.
          It must be the same shape as `input`, and of type float64 if `metric`
          is 'euclidean', uint32 otherwise.
      indices : int32 ndarray, optional
          An output array to store the calculated feature transform, instead of
          returning it.
          `return_indicies` must be True.
          Its shape must be `(input.ndim,) + input.shape`.
  
      Returns
      -------
      distances : 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.
      indices : int32 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.
  
      """
      ft_inplace = isinstance(indices, numpy.ndarray)
      dt_inplace = isinstance(distances, numpy.ndarray)
      _distance_tranform_arg_check(
          dt_inplace, ft_inplace, return_distances, return_indices
      )
  
      tmp1 = numpy.asarray(input) != 0
      struct = generate_binary_structure(tmp1.ndim, tmp1.ndim)
      tmp2 = binary_dilation(tmp1, struct)
      tmp2 = numpy.logical_xor(tmp1, tmp2)
      tmp1 = tmp1.astype(numpy.int8) - tmp2.astype(numpy.int8)
      metric = metric.lower()
      if metric == "euclidean":
          metric = 1
      elif metric in ["taxicab", "cityblock", "manhattan"]:
          metric = 2
      elif metric == "chessboard":
          metric = 3
      else:
          raise RuntimeError("distance metric not supported")
      if sampling is not None:
          sampling = _ni_support._normalize_sequence(
              sampling, tmp1.ndim
          )
          sampling = numpy.asarray(sampling, dtype=numpy.float64)
          if not sampling.flags.contiguous:
              sampling = sampling.copy()
      if return_indices:
          ft = numpy.zeros(tmp1.shape, dtype=numpy.int32)
      else:
          ft = None
      if return_distances:
          if distances is None:
              if metric == 1:
                  dt = numpy.zeros(tmp1.shape, dtype=numpy.float64)
              else:
                  dt = numpy.zeros(tmp1.shape, dtype=numpy.uint32)
          else:
              if distances.shape != tmp1.shape:
                  raise RuntimeError("distances array has wrong shape")
              if metric == 1:
                  if distances.dtype.type != numpy.float64:
                      raise RuntimeError(
                          "distances array must be float64"
                      )
              else:
                  if distances.dtype.type != numpy.uint32:
                      raise RuntimeError(
                          "distances array must be uint32"
                      )
              dt = distances
      else:
          dt = None
  
      _nd_image.distance_transform_bf(tmp1, metric, sampling, dt, ft)
      if return_indices:
          if isinstance(indices, numpy.ndarray):
              if indices.dtype.type != numpy.int32:
                  raise RuntimeError("indices array must be int32")
              if indices.shape != (tmp1.ndim,) + tmp1.shape:
                  raise RuntimeError("indices array has wrong shape")
              tmp2 = indices
          else:
              tmp2 = numpy.indices(tmp1.shape, dtype=numpy.int32)
          ft = numpy.ravel(ft)
          for ii in range(tmp2.shape[0]):
              rtmp = numpy.ravel(tmp2[ii, ...])[ft]
              rtmp.shape = tmp1.shape
              tmp2[ii, ...] = rtmp
          ft = tmp2
  
      # construct and return the result
      result = []
      if return_distances and not dt_inplace:
          result.append(dt)
      if return_indices and not ft_inplace:
          result.append(ft)
  
      if len(result) == 2:
          return tuple(result)
      elif len(result) == 1:
          return result[0]
      else:
          return None
  
imports: import warnings
  import operator
  import numpy
  from .None import _ni_support
  from .None import _nd_image
  from .None import filters
label_desc: Use image node_id 20 for calling a global function with example usage: distance_transform_bf(input, metric, sampling, return_distances, return_indices, distances, indices) and returns: tuple, result, None