class_docstr: Create a rank filter.  The rank filter sorts all pixels in
  a window of the given size, and returns the ``rank``'th value.
  
  :param size: The kernel size, in pixels.
  :param rank: What pixel value to pick.  Use 0 for a min filter,
               ``size * size / 2`` for a median filter, ``size * size - 1``
               for a max filter, etc.
class_docstr_tok: ["Create","a","rank","filter",".","The","rank","filter","sorts","all","pixels","in","a","window","of","the","given","size",",","and","returns","the","``","rank","``","'th","value",".",":","param","size",":","The","kernel","size",",","in","pixels",".",":","param","rank",":","What","pixel","value","to","pick",".","Use","0","for","a","min","filter",",","``","size","*","size","\/","2","``","for","a","median","filter",",","``","size","*","size","-","1","``","for","a","max","filter",",","etc","."]
code: def filter(self, image):
      if image.mode == "P":
          msg = "cannot filter palette images"
          raise ValueError(msg)
      image = image.expand(self.size // 2, self.size // 2)
      return image.rankfilter(self.size, self.rank)
  
imports: from __future__ import annotations
  import functools
label_desc: Use image node_id 2 for calling the RankFilter obj's underlying member method code with example usage: obj.filter(image) and returns: image