code: def slow_reg(A, agg):
      def get(i, j):
          vals = []
  
          def try_this(i, j):
              if 0 <= i < A.shape[0] and 0 <= j < A.shape[1]:
                  vals.append(A[i, j])
  
          try_this(i, j)
          try_this(i - 1, j)
          try_this(i + 1, j)
          try_this(i, j - 1)
          try_this(i, j + 1)
          return vals
  
      res = np.zeros(A.shape, np.bool_)
      for i in range(A.shape[0]):
          for j in range(A.shape[0]):
              res[i, j] = A[i, j] == agg(get(i, j))
      return res
  
imports: import mahotas
  import numpy
  from mahotas.morph import get_structuring_elem, subm, tophat_open, tophat_close
  import pytest
label_desc: Use image node_id 4 for calling a global function with example usage: slow_reg(A, agg) and returns: res, vals