# Recipe38: Posterise to two grey levels

def greyposterise(pic):

  for p in getPixels(pic):
    r = getRed(p)
    g = getGreen(p)
    b = getBlue(p)

    luminance = (r+g+b)/3

    if (luminance < 128):
      setColor(p,black)
    if (luminance >= 128):
      setColor(p,white)

