我需要在python中更改图像的像素颜色.除了像素值(255,0,0)红外,我需要将每个像素颜色值更改为黑色(0,0,0).我尝试了以下代码但它没有帮助.
from PIL import Image
im = Image.open('A:\ex1.jpg')
for pixel in im.getdata():
if pixel == (255,0,0):
print "Red coloured pixel"
else:
pixel = [0, 0, 0]
Run Code Online (Sandbox Code Playgroud)