如何更改图像的rgb分量的值
问题描述:
我想解析图像的r,g,b矩阵以进行更改,然后再将它们应用于图像。我已经使用PhotoImage
函数来显示图像:如何更改图像的rgb分量的值
img=Photoimage(filename)
for i in range (0,500):
for j in range (0,500):
pixel=img.get(i,j)
这回我的每一个像素的RGB值,但我不能够使图像的像素值的变化。
我使用load()
,imread()
,getpixel()
,getred()
..但这些似乎并没有与Python 3
任何建议合作试过吗?
答
我已经使用PIL要做到这一点,在过去,这里是我使用的代码,它读取它作为一个单一的值,而不是RGB,因为它似乎只与GIF格式的工作:
f="path\to\image.gif"
from PIL import Image, ImageTk
img = Image.open(f)
pix=list(img.getdata())
width=img.size[0]
height=img.size[1]
#modify the image here
for i in pix:
print(i)
img.putdata(pix)
photo.paste(img)
img.close()
希望这有助于。