0

I am trying to import an image, then manipulate its rgb colors. This is what i've got:

from PIL import Image
image = Image.open('grapes.jpg')
pixels = list(image.getdata())

for pixel in pixels:
    pixel = (pixel[0] - 50, pixel[1] , pixel[2])

image.putdata(pixel)
image.save('grapes_modified.jpg')

as you can see, i am trying to reduce the red channel. This doesn't work. It produces the exact duplicate of the imported image. even if i where to do something like this: pixel = (0,0,0). It would produce a duplicate image.

so how do i modify the image?

thanks,

1 Answer 1

3

The for cycle doesn't replace the content of each pixel, it just creates a new instance and then tosses it away. You should create a new array, for example:

newdata = [ (pixel[0] - 50, pixel[1] , pixel[2]) for pixel in pixels ]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.