I have a piece of code that will return a flat sequence for each pixel in the 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)
These codes return 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 pixels, and the last is the index in the sequence. Knowing the width and height of the image and the pixel index in a sequence, how can I convert this sequence back to a 2d sequence?