1from PIL import Image
2
3img = Image.open('example.png')
4imgWidth, imgHeight = img.size
5img = img.convert("RGBA")
6imgdata = img.getdata()
7
8x_pos = 0
9y_pos = 1
10
11pixel_value = []
12x = []
13y = []
14
15for item in imgdata:
16 if (x_pos) == imgWidth:
17 x_pos = 1
18 y_pos += 1
19 else:
20 x_pos += 1
21
22 if item[3] != 0:
23 pixel_value.append(item[2])
24 x.append(x_pos)
25 y.append(y_pos)
26
27pixel_value, x, y = zip(*sorted(zip(pixel_value, x, y), reverse=True))
28
29print(f'{pixel_value}\n{x}\n{y}')