code: def _slow_rank_filter(A, r):
      B = np.zeros_like(A)
      for i in range(A.shape[0]):
          for j in range(A.shape[1]):
              s0 = max(0, i - 1)
              s1 = max(0, j - 1)
              e0 = min(A.shape[0], i + 2)
              e1 = min(A.shape[1], j + 2)
              pixels = list(A[s0:e0, s1:e1].ravel())
              pixels.extend([0] * (9 - len(pixels)))
              pixels.sort()
              B[i, j] = pixels[r]
      return B
  
file_path: mahotas/mahotas/tests/test_median_filter.py
imports: import numpy
  from mahotas.convolve import median_filter, rank_filter
  import pytest
label_desc: Use image node_id 2 for calling a global function with example usage: _slow_rank_filter(A, r) and returns: B