code: def distance_transform_edt(
      input,
      sampling=None,
      return_distances=True,
      return_indices=False,
      distances=None,
      indices=None,
  ):
      """
      Exact euclidean distance transform.
  
      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 data to transform. Can be any type but will be converted
          into binary: 1 wherever input equates to True, 0 elsewhere.
      sampling : float or int, or sequence of same, optional
          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 return distance matrix. At least one of
          return_distances/return_indices must be True. Default is True.
      return_indices : bool, optional
          Whether to return indices matrix. Default is False.
      distances : ndarray, optional
          Used for output of distance array, must be of type float64.
      indices : ndarray, optional
          Used for output of indices, must be of type int32.
  
      Returns
      -------
      distance_transform_edt : ndarray or list of ndarrays
          Either distance matrix, index matrix, or a list of the two,
          depending on `return_x` flags and `distance` and `indices`
          input parameters.
  
      Notes
      -----
      The euclidean distance transform gives values of the euclidean
      distance::
  
                      n
        y_i = sqrt(sum (x[i]-b[i])**2)
                      i
  
      where b[i] is the background point (value 0) with the smallest
      Euclidean distance to input points x[i], and n is the
      number of dimensions.
  
      Examples
      --------
      >>> from scipy import ndimage
      >>> a = np.array(([0,1,1,1,1],
      ...               [0,0,1,1,1],
      ...               [0,1,1,1,1],
      ...               [0,1,1,1,0],
      ...               [0,1,1,0,0]))
      >>> ndimage.distance_transform_edt(a)
      array([[ 0.    ,  1.    ,  1.4142,  2.2361,  3.    ],
             [ 0.    ,  0.    ,  1.    ,  2.    ,  2.    ],
             [ 0.    ,  1.    ,  1.4142,  1.4142,  1.    ],
             [ 0.    ,  1.    ,  1.4142,  1.    ,  0.    ],
             [ 0.    ,  1.    ,  1.    ,  0.    ,  0.    ]])
  
      With a sampling of 2 units along x, 1 along y:
  
      >>> ndimage.distance_transform_edt(a, sampling=[2,1])
      array([[ 0.    ,  1.    ,  2.    ,  2.8284,  3.6056],
             [ 0.    ,  0.    ,  1.    ,  2.    ,  3.    ],
             [ 0.    ,  1.    ,  2.    ,  2.2361,  2.    ],
             [ 0.    ,  1.    ,  2.    ,  1.    ,  0.    ],
             [ 0.    ,  1.    ,  1.    ,  0.    ,  0.    ]])
  
      Asking for indices as well:
  
      >>> edt, inds = ndimage.distance_transform_edt(a, return_indices=True)
      >>> inds
      array([[[0, 0, 1, 1, 3],
              [1, 1, 1, 1, 3],
              [2, 2, 1, 3, 3],
              [3, 3, 4, 4, 3],
              [4, 4, 4, 4, 4]],
             [[0, 0, 1, 1, 4],
              [0, 1, 1, 1, 4],
              [0, 0, 1, 4, 4],
              [0, 0, 3, 3, 4],
              [0, 0, 3, 3, 4]]])
  
      With arrays provided for inplace outputs:
  
      >>> indices = np.zeros(((np.ndim(a),) + a.shape), dtype=np.int32)
      >>> ndimage.distance_transform_edt(a, return_indices=True, indices=indices)
      array([[ 0.    ,  1.    ,  1.4142,  2.2361,  3.    ],
             [ 0.    ,  0.    ,  1.    ,  2.    ,  2.    ],
             [ 0.    ,  1.    ,  1.4142,  1.4142,  1.    ],
             [ 0.    ,  1.    ,  1.4142,  1.    ,  0.    ],
             [ 0.    ,  1.    ,  1.    ,  0.    ,  0.    ]])
      >>> indices
      array([[[0, 0, 1, 1, 3],
              [1, 1, 1, 1, 3],
              [2, 2, 1, 3, 3],
              [3, 3, 4, 4, 3],
              [4, 4, 4, 4, 4]],
             [[0, 0, 1, 1, 4],
              [0, 1, 1, 1, 4],
              [0, 0, 1, 4, 4],
              [0, 0, 3, 3, 4],
              [0, 0, 3, 3, 4]]])
  
      """
      if (not return_distances) and (not return_indices):
          msg = "at least one of distances/indices must be specified"
          raise RuntimeError(msg)
  
      ft_inplace = isinstance(indices, numpy.ndarray)
      dt_inplace = isinstance(distances, numpy.ndarray)
      # calculate the feature transform
      input = numpy.atleast_1d(
          numpy.where(input, 1, 0).astype(numpy.int8)
      )
      if sampling is not None:
          sampling = _ni_support._normalize_sequence(
              sampling, input.ndim
          )
          sampling = numpy.asarray(sampling, dtype=numpy.float64)
          if not sampling.flags.contiguous:
              sampling = sampling.copy()
  
      if ft_inplace:
          ft = indices
          if ft.shape != (input.ndim,) + input.shape:
              raise RuntimeError("indices has wrong shape")
          if ft.dtype.type != numpy.int32:
              raise RuntimeError("indices must be of int32 type")
      else:
          ft = numpy.zeros(
              (input.ndim,) + input.shape, dtype=numpy.int32
          )
  
      _nd_image.euclidean_feature_transform(input, sampling, ft)
      # if requested, calculate the distance transform
      if return_distances:
          dt = ft - numpy.indices(input.shape, dtype=ft.dtype)
          dt = dt.astype(numpy.float64)
          if sampling is not None:
              for ii in range(len(sampling)):
                  dt[ii, ...] *= sampling[ii]
          numpy.multiply(dt, dt, dt)
          if dt_inplace:
              dt = numpy.add.reduce(dt, axis=0)
              if distances.shape != dt.shape:
                  raise RuntimeError("indices has wrong shape")
              if distances.dtype.type != numpy.float64:
                  raise RuntimeError("indices must be of float64 type")
              numpy.sqrt(dt, distances)
          else:
              dt = numpy.add.reduce(dt, axis=0)
              dt = numpy.sqrt(dt)
  
      # 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: 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 22 for calling a global function with example usage: distance_transform_edt(input, sampling, return_distances, return_indices, distances, indices) and returns: tuple, result, None