1

When I run this code, I get a single value for the pixel,now I don't know what the single value represents..red, green, blue, or some average of them all.

I was wondering how I can get all the values of RGB separate, like in a tuple or some other source so I can change each one separately.

from PIL import Image

img = Image.open("flower.jpg")
img = img.convert("L")
pix = img.load()

img.save('test2.jpg')



h = img.size[0]
w = img.size[1]

for x in range(h):
    for y in range(w):
        xy = (x, y)
        pix = img.getpixel(xy)


    print(pix[x,y])
Sachith Muhandiram
  • 2,819
  • 10
  • 45
  • 94
Teemo
  • 11
  • 1
  • Could you post the single values you are receiving in place of the RBG? It may help me figure out what's going on. – Qwerty Dec 06 '16 at 02:34
  • I can post them, but the image is 600 x 480, so the there is ~20000 values that I am getting every time I run it, and it's between 0-255 as it should be. – Teemo Dec 06 '16 at 02:35
  • That works there @furas. I am slightly confused on why it did work though. is it because it's converted to 'RGB' instead of 'L'? – Teemo Dec 06 '16 at 02:38
  • see doc [PIL.Image.Image.convert()](http://pillow.readthedocs.io/en/3.4.x/reference/Image.html#PIL.Image.Image.convert). `L` converts to grayscale and every pixel has value 0-255. So RGB for pixel is `r = g = b = getpixel()` – furas Dec 06 '16 at 02:47

0 Answers0