What does the getdata() function of Pillow module return?

  python, python-imaging-library

I am sorry, it may be a silly question but i don’t understand what is that sequence "getData()" of the pillow image module returns, i read that it returns the value of the image pixel, but it returns a list of four elements, i thought that the first three elements represent the RGB values and the fourth is the highest intensity (255), however i followed a guide for getting the pixels of an image, and here is the code

from PIL import Image

img = Image.open('example.png')
imgWidth, imgHeight = img.size
img = img.convert("RGBA")
imgdata = img.getdata()

x_pos = 0
y_pos = 1

pixel_value = []
x = []
y = []

for item in imgdata:
   if (x_pos) == imgWidth:
        x_pos = 1
        y_pos += 1
   else:
        x_pos += 1

   if item[3] != 0:
        pixel_value.append(item[2])
        x.append(x_pos)
        y.append(y_pos)

   pixel_value, x, y = zip(*sorted(zip(pixel_value, x, y), reverse=True))

   print(f'{pixel_value}n{x}n{y}')

Now why does he only append the second elements as if it’s as how i understand, it only represents the blue intensity value !

Source: Python Questions

LEAVE A COMMENT