from itertools import product from PIL import Image
img = Image.open('test.png') width, height = img.size for pos in product(range(width), range(height)): if sum(img.getpixel(pos)[:3]) > 600: img.putpixel(pos, (255,255,255)) img.save('removed_1.png')
运行结果,对比一下。
与第一种方法对比,肉眼也没看出来太明显差别。
那大家就喜欢那种方法就用哪个吧!
参考资料
[1]
How to remove watermark background in image Python: https://stackoverflow.com/questions/50792812/how-to-remove-watermark-background-in-image-python?answertab=oldest#tab-top