code: def generic_filter(
      input,
      function,
      size=None,
      footprint=None,
      output=None,
      mode="reflect",
      cval=0.0,
      origin=0,
      extra_arguments=(),
      extra_keywords=None,
  ):
      """Calculate a multi-dimensional filter using the given function.
  
      At each element the provided function is called. The input values
      within the filter footprint at that element are passed to the function
      as a 1D array of double values.
  
      Parameters
      ----------
      %(input)s
      function : {callable, scipy.LowLevelCallable}
          Function to apply at each element.
      %(size_foot)s
      %(output)s
      %(mode_multiple)s
      %(cval)s
      %(origin_multiple)s
      %(extra_arguments)s
      %(extra_keywords)s
  
      Notes
      -----
      This function also accepts low-level callback functions with one of
      the following signatures and wrapped in `scipy.LowLevelCallable`:
  
      .. code:: c
  
         int callback(double *buffer, npy_intp filter_size,
                      double *return_value, void *user_data)
         int callback(double *buffer, intptr_t filter_size,
                      double *return_value, void *user_data)
  
      The calling function iterates over the elements of the input and
      output arrays, calling the callback function at each element. The
      elements within the footprint of the filter at the current element are
      passed through the ``buffer`` parameter, and the number of elements
      within the footprint through ``filter_size``. The calculated value is
      returned in ``return_value``. ``user_data`` is the data pointer provided
      to `scipy.LowLevelCallable` as-is.
  
      The callback function must return an integer error status that is zero
      if something went wrong and one otherwise. If an error occurs, you should
      normally set the python error status with an informative message
      before returning, otherwise a default error message is set by the
      calling function.
  
      In addition, some other low-level function pointer specifications
      are accepted, but these are for backward compatibility only and should
      not be used in new code.
  
      """
      if (size is not None) and (footprint is not None):
          warnings.warn(
              "ignoring size because footprint is set",
              UserWarning,
              stacklevel=2,
          )
      if extra_keywords is None:
          extra_keywords = {}
      input = numpy.asarray(input)
      if numpy.iscomplexobj(input):
          raise TypeError("Complex type not supported")
      origins = _ni_support._normalize_sequence(origin, input.ndim)
      if footprint is None:
          if size is None:
              raise RuntimeError("no footprint or filter size provided")
          sizes = _ni_support._normalize_sequence(size, input.ndim)
          footprint = numpy.ones(sizes, dtype=bool)
      else:
          footprint = numpy.asarray(footprint, dtype=bool)
      fshape = [ii for ii in footprint.shape if ii > 0]
      if len(fshape) != input.ndim:
          raise RuntimeError(
              "filter footprint array has incorrect shape."
          )
      for origin, lenf in zip(origins, fshape):
          if (lenf // 2 + origin < 0) or (lenf // 2 + origin >= lenf):
              raise ValueError("invalid origin")
      if not footprint.flags.contiguous:
          footprint = footprint.copy()
      output = _ni_support._get_output(output, input)
      mode = _ni_support._extend_mode_to_code(mode)
      _nd_image.generic_filter(
          input,
          function,
          footprint,
          output,
          mode,
          cval,
          origins,
          extra_arguments,
          extra_keywords,
      )
      return output
  
imports: from __future__ import division, print_function, absolute_import
  import warnings
  import numbers
  import numpy
  import operator
  from .None import _ni_support
  from .None import _nd_image
  from .None import _ni_docstrings
label_desc: Use image node_id 29 for calling a global function with example usage: generic_filter(input, function, size, footprint, output, mode, cval, origin, extra_arguments, extra_keywords) and returns: output