code: def _neighbors(image):
      """
  
      Counts the neighbor pixels for each pixel of an image:
  
              x = [
                  [0, 1, 0],
                  [1, 1, 1],
                  [0, 1, 0]
              ]
  
              _neighbors(x)
  
              [
                  [0, 3, 0],
                  [3, 4, 3],
                  [0, 3, 0]
              ]
  
      :type image: numpy.ndarray
  
      :param image: A two-or-three dimensional image
  
      :return: neighbor pixels for each pixel of an image
  
      """
      padding = numpy.pad(image, 1, "constant")
  
      mask = padding > 0
  
      padding = padding.astype(float)
  
      if image.ndim == 2:
          response = 3**2 * scipy.ndimage.uniform_filter(padding) - 1
  
          labels = (response * mask)[1:-1, 1:-1]
  
          return labels.astype(numpy.uint16)
      elif image.ndim == 3:
          response = 3**3 * scipy.ndimage.uniform_filter(padding) - 1
  
          labels = (response * mask)[1:-1, 1:-1, 1:-1]
  
          return labels.astype(numpy.uint16)
  
imports: import numpy
  import scipy.ndimage
  import skimage.segmentation
  import skimage.util
  from cellprofiler_core.module import Module
  from cellprofiler_core.setting.subscriber import ImageSubscriber
label_desc: Use image node_id 1 for calling a global function with example usage: _neighbors(image) and returns: labels, labels