要获得纯净的0,255两种灰度的图片,可以采用new 一个Image对象,模式为‘1’,再用阈值判断进行draw方法,代码:
from PIL import Image, ImageDraw
img2 = Image.new("1", img.size)
draw = ImageDraw.Draw(img2)
for x in range(0, img2.size[0]):
for y in range(0, img2.size[1]):
draw.point((x, y), t2val[(x, y)])
return img2