python3 图片去水印

#去掉水印
from itertools import product
from PIL import Image
def Remove_watermark(fileName,saveFile):
    img1 = Image.open(fileName)
    # img1如果不是RGB模式,需要转成RGB模式
    # print(img1.mode)
    img = img1.convert('RGB')
    # print(img.mode)
    width, height = img.size
    for pos in product(range(width), range(height)):
        #600是经验值,需要根据实际情况调整
        if sum(img.getpixel(pos)[:3]) > 600:
            img.putpixel(pos, (255, 255, 255))
    img.save(saveFile)

 

posted on 2022-10-12 14:33  shaomine  阅读(324)  评论(0编辑  收藏  举报