python 替换图片中的像素

python 替换图片中的像素

 

from PIL import Image
import time
img = Image.open('luban/jietu1631965285306c.jpg')
img = img.convert('RGB')
pixels = img.load()
start=time.time()

for i in range(img.size[0]):

    for j in range(img.size[1]):
        if (pixels[i,j][0]>=90 and pixels[i,j][0]<=160) and (pixels[i,j][1]>=130 and pixels[i,j][1]<=220) and (pixels[i,j][2]>=150 and pixels[i,j][2]<=240):

        # if pixels[i,j] == (225, 225, 225):
        #     print('wefwef');

            pixels[i,j] = (0,0,0)

img.save('example.jpg')
end=time.time()
print('Running time: %s Seconds'%(end-start))

 

posted @ 2021-10-03 12:04  newmiracle宇宙  阅读(361)  评论(0编辑  收藏  举报