code: def _neighbours(bwimg, y, x, n):
      s0 = max(0, y - 1)
      e0 = min(y + 2, bwimg.shape[0])
      s1 = max(0, x - 1)
      e1 = min(x + 2, bwimg.shape[1])
      if n == 8:
          return bwimg[s0:e0, s1:e1]
      return np.concatenate([bwimg[s0:e0, x], bwimg[y, s1:e1]])
  
imports: from mahotas import bwperim
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: _neighbours(bwimg, y, x, n) and returns: np, bwimg