def threshold_mean(img, thresh_multiplier=0.95, color1=255, color2=0):
    """Threshold a greyscale image using mean thresholding."""
    mean = img.mean()
    ret = mean * thresh_multiplier
    img[img > ret] = color1
    img[img < ret] = color2
    return img