使用 python3 的 PIL 库,使用其中 Image.open 方法打开,然后使用 getpixel() 方法获取像素信息,若为白色则使用 putpixel() 改为红色。
但选区不会选,只能大致改一下,若有解决方法请指教 ^_^
from PIL import Image as image
img = image.open("d:\\2.jpg")
p = img.getpixel( tuple(map(lambda x:x//10, img.size)) )
w,h = img.size
for x in range(w-1):
for y in range(h-1):
try:
if img.getpixel( (x,y) ) > (240,240,240) and img.getpixel( (x,y+1) ) > (240,240,240) and img.getpixel( (x,y-1) ) > (240,240,240) and img.getpixel( (x+1,y) ) > (240,240,240) and img.getpixel( (x-1,y) ) > (240,240,240):
img.putpixel( (x,y), (255,0,0) )
except:
img.putpixel( (x,y), (255,0,0) )
img.save("3.jpg")
img.show()
print("successful convernt!")
(本文会继续更新)