python - 图片灰度化、二值化
1. 灰度化
from PIL import Image
img = Image.open("test.jpg")
img = img.convert("L")
img.save("output.jpg")
2. 二值化
from PIL import Image
img = Image.open("test.jpg")
img = img.convert("L")
threshold = 180
table = [x > threshold for x in range(256)]
img = img.point(table, "1")
img.save("output.jpg")