Take the 2-minute tour ×

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


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?


share|improve this question

1 Answer 1

up vote 3 down vote accepted

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 ]
share|improve this answer

Your Answer


