抽取反差色图像是每个像素跟0x1位与运算,结果为0的像素,设置为0,其他设置为255。
from PIL import Image
img = Image.open('01.jpg')
width,height=img.size
for i in range(0,width):
for j in range(0,height):
tmp = img.getpixel((i,j))
if tmp&0x1 == 0:
img.putpixel((i,j),0)
else:
img.putpixel((i,j),255)
img.show()