I have a piece of code that will return a flat sequence for every pixel in a image.
import Image
im = Image.open("test.png")
print("Picture size is ", width, height)
data = list(im.getdata())
for n in range(width*height):
if data[n] == (0, 0, 0):
print(data[n], n)
This codes returns something like this
((0, 0, 0), 1250)
((0, 0, 0), 1251)
((0, 0, 0), 1252)
((0, 0, 0), 1253)
((0, 0, 0), 1254)
((0, 0, 0), 1255)
((0, 0, 0), 1256)
((0, 0, 0), 1257)
The first three values are the RGB of the pixel and the last one is the index in the sequence. Knowing the width and height of the image and the pixels index in sequence how can i convert that sequence back into a 2d sequence?