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 is returned along the first axis of the result.
  
      Parameters
      ----------
      input : array_like
          Input
      metric : str, 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_distances : bool, optional
          The `return_distances` flag can be used to indicate if the distance
          transform is returned.
  
          The default is True.
      return_indices : bool, optional
          The `return_indices` flags can be used to indicate if the feature
          transform is returned.
  
          The default is False.
      distances : float64 ndarray, optional
          Optional output array to hold distances (if `return_distances` is
          True).
      indices : int64 ndarray, optional
          Optional output array to hold indices (if `return_indices` is True).
  
      Returns
      -------
      distances : ndarray
          Distance array if `return_distances` is True.
      indices : ndarray
          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.
  
      """
      if (not return_distances) and (not return_indices):
          msg = "at least one of distances/indices must be specified"
          raise RuntimeError(msg)
  
      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 must of int32 type")
              if indices.shape != (tmp1.ndim,) + tmp1.shape:
                  raise RuntimeError("indices 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 isinstance(distances, numpy.ndarray):
          result.append(dt)
      if return_indices and not isinstance(indices, numpy.ndarray):
          result.append(ft)
  
      if len(result) == 2:
          return tuple(result)
      elif len(result) == 1:
          return result[0]
      else:
          return None
  
imports: from __future__ import division, print_function, absolute_import
  import warnings
  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