code: def rank_filter(
      input,
      rank,
      size=None,
      footprint=None,
      output=None,
      mode="reflect",
      cval=0.0,
      origin=0,
  ):
      """Calculate a multidimensional rank filter.
  
      Parameters
      ----------
      %(input)s
      rank : int
          The rank parameter may be less then zero, i.e., rank = -1
          indicates the largest element.
      %(size_foot)s
      %(output)s
      %(mode_reflect)s
      %(cval)s
      %(origin_multiple)s
  
      Returns
      -------
      rank_filter : ndarray
          Filtered array. Has the same shape as `input`.
  
      Examples
      --------
      >>> from scipy import ndimage, misc
      >>> import matplotlib.pyplot as plt
      >>> fig = plt.figure()
      >>> plt.gray()  # show the filtered result in grayscale
      >>> ax1 = fig.add_subplot(121)  # left side
      >>> ax2 = fig.add_subplot(122)  # right side
      >>> ascent = misc.ascent()
      >>> result = ndimage.rank_filter(ascent, rank=42, size=20)
      >>> ax1.imshow(ascent)
      >>> ax2.imshow(result)
      >>> plt.show()
      """
      rank = operator.index(rank)
      return _rank_filter(
          input,
          rank,
          size,
          footprint,
          output,
          mode,
          cval,
          origin,
          "rank",
      )
  
imports: from collections.abc import Iterable
  import warnings
  import numpy
  import operator
  from numpy.core.multiarray import normalize_axis_index
  from .None import _ni_support
  from .None import _nd_image
  from .None import _ni_docstrings
label_desc: Use image node_id 26 for calling a global function with example usage: rank_filter(input, rank, size, footprint, output, mode, cval, origin) and returns: _rank_filter