code: def _generic_edge_filter(
      image,
      *,
      smooth_weights,
      edge_weights=[1, 0, -1],
      axis=None,
      mode="reflect",
      cval=0.0,
      mask=None,
  ):
      """Apply a generic, n-dimensional edge filter.
  
      The filter is computed by applying the edge weights along one dimension
      and the smoothing weights along all other dimensions. If no axis is given,
      or a tuple of axes is given the filter is computed along all axes in turn,
      and the magnitude is computed as the square root of the average square
      magnitude of all the axes.
  
      Parameters
      ----------
      image : array
          The input image.
      smooth_weights : array of float
          The smoothing weights for the filter. These are applied to dimensions
          orthogonal to the edge axis.
      edge_weights : 1D array of float, optional
          The weights to compute the edge along the chosen axes.
      axis : int or sequence of int, optional
          Compute the edge filter along this axis. If not provided, the edge
          magnitude is computed. This is defined as::
  
              edge_mag = np.sqrt(sum([_generic_edge_filter(image, ..., axis=i)**2
                                      for i in range(image.ndim)]) / image.ndim)
  
          The magnitude is also computed if axis is a sequence.
      mode : str or sequence of str, optional
          The boundary mode for the convolution. See `scipy.ndimage.convolve`
          for a description of the modes. This can be either a single boundary
          mode or one boundary mode per axis.
      cval : float, optional
          When `mode` is ``'constant'``, this is the constant used in values
          outside the boundary of the image data.
      """
      ndim = image.ndim
      if axis is None:
          axes = list(range(ndim))
      elif np.isscalar(axis):
          axes = [axis]
      else:
          axes = axis
      return_magnitude = len(axes) > 1
  
      if image.dtype.kind == "f":
          float_dtype = _supported_float_type(image.dtype)
          image = image.astype(float_dtype, copy=False)
      else:
          image = img_as_float(image)
      output = np.zeros(image.shape, dtype=image.dtype)
  
      for edge_dim in axes:
          kernel = _reshape_nd(edge_weights, ndim, edge_dim)
          smooth_axes = list(set(range(ndim)) - {edge_dim})
          for smooth_dim in smooth_axes:
              kernel = kernel * _reshape_nd(
                  smooth_weights, ndim, smooth_dim
              )
          ax_output = ndi.convolve(image, kernel, mode=mode)
          if return_magnitude:
              ax_output *= ax_output
          output += ax_output
  
      if return_magnitude:
          output = np.sqrt(output) / np.sqrt(ndim)
      return output
  
imports: import numpy
  from scipy import ndimage
  from scipy.ndimage import binary_erosion, convolve
  from .._shared.utils import _supported_float_type, check_nD
  from ..restoration.uft import laplacian
  from ..util.dtype import img_as_float
label_desc: Use image node_id 4 for calling a global function with example usage: _generic_edge_filter(image) and returns: output