import numpy as np
from PIL import Image
import skimage.io
img = Image.open(file_name)
img = img.convert("L")
imgs = skimage.io.imread(file_name)
ttt = np.mean(imgs)
WHITE, BLACK = 255, 0
img = img.point(lambda x: WHITE if x > ttt else BLACK)
img = img.convert('1')
img.save(new_file_name)