code: def _rank_filter(
      input,
      rank,
      size=None,
      footprint=None,
      output=None,
      mode="reflect",
      cval=0.0,
      origin=0,
      operation="rank",
  ):
      if (size is not None) and (footprint is not None):
          warnings.warn(
              "ignoring size because footprint is set",
              UserWarning,
              stacklevel=3,
          )
      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()
      filter_size = numpy.where(footprint, 1, 0).sum()
      if operation == "median":
          rank = filter_size // 2
      elif operation == "percentile":
          percentile = rank
          if percentile < 0.0:
              percentile += 100.0
          if percentile < 0 or percentile > 100:
              raise RuntimeError("invalid percentile")
          if percentile == 100.0:
              rank = filter_size - 1
          else:
              rank = int(float(filter_size) * percentile / 100.0)
      if rank < 0:
          rank += filter_size
      if rank < 0 or rank >= filter_size:
          raise RuntimeError("rank not within filter footprint size")
      if rank == 0:
          return minimum_filter(
              input, None, footprint, output, mode, cval, origins
          )
      elif rank == filter_size - 1:
          return maximum_filter(
              input, None, footprint, output, mode, cval, origins
          )
      else:
          output = _ni_support._get_output(output, input)
          mode = _ni_support._extend_mode_to_code(mode)
          _nd_image.rank_filter(
              input, rank, footprint, output, mode, cval, origins
          )
          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 24 for calling a global function with example usage: _rank_filter(input, rank, size, footprint, output, mode, cval, origin, operation) and returns: minimum_filter, maximum_filter, output