0

I'm trying to loop through each pixel of an image, process that pixel, and set the pixel to a new color.

I've tried using Pillow:

from PIL import Image
picture = Image.open("image.png")

# Get the size of the image
width, height = picture.size

# Process every pixel
for x in range(0, width):
    for y in range(0, height):
        current_color = picture.getpixel( (x,y) )
        print(current_color)
        new_color = processPixel(current_color)
        picture.putpixel( (x,y), new_color)

But printing current_color just prints 0 for each pixel in the image

Here is the picture I'm using

Param
  • 609
  • 2
  • 5
  • 16

1 Answers1

0

Use picture.size without parentheses.

As for the printed color, the picture you posted has "P" mode in PIL, which is not "RGB" mode, hence the zeros you get.

Inon Peled
  • 691
  • 4
  • 11