code: def count_neighbours(mask, radius=1):
      '''Count how many neighbours of a coordinate are set to one.
      This uses the same principles as anti_alias, compare comments there.'''
  
      height, width = mask.shape
  
      f = 2.0*radius+1.0
  
      w = -1.0/numpy.sqrt(f)
      kernel = [w]*radius + [w] + [w]*radius
  
      result = mask * f
  
      for y in range(height):
          result[y,:]  = numpy.convolve(result[y,:], kernel, 'same')
  
      for x in range(width):
          result[:,x] = numpy.convolve(result[:, x], kernel, 'same')
  
      return result - masf count_neighbours(mask, radius=1):
      '''Count how many neighbours of a coordinate are set to one.
      This uses the same principles as anti_alias, compare comments there.'''
  
      height, width = mask.shape
  
      f = 2.0*radius+1.0
  
      w = -1.0/numpy.sqrt(f)
      kernel = [w]*radius + [w] + [w]*radius
  
      result = mask * f
  
      for y in range(height):
          result[y,:]  = numpy.convolve(result[y,:], kernel, 'same')
  
      for x in range(width):
          result[:,x] = numpy.convolve(result[:, x], kernel, 'same')
  
      return result - mask
docs: Count how many neighbours of a coordinate are set to one.
      This uses the same principles as anti_alias, compare comments there.