简体   繁体   中英

how to change the value of rgb component of an image

I want to parse r,g,b matrix of an image to make changes and then again apply them on to a image. I have used PhotoImage function to display the image:

img=Photoimage(filename)
for i in range (0,500):
    for j in range (0,500):
        pixel=img.get(i,j)

This is returning me the rgb value of every pixel but i am not able to make changes in the pixel value of image.
I tried using load() , imread() , getpixel() , getred() .. but these do not seem to be working with Python 3.
Any suggestions?

I have used PIL to do this in the past, here is the code I used, It reads it as a single value rather than as RGB as it only seems to work with GIFs:

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()

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM