相关疑难解决方法(0)

更改PIL中的像素颜色值

我需要在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)

python python-imaging-library

9
推荐指数
4
解决办法
3万
查看次数

标签 统计

python ×1

python-imaging-library ×1