Upload image as a pixel matris
reutersward (0)

I want to upload an image from my computer, and get the corresponding pixel matrix. No idea how to start.

You are viewing a single comment. View All
mwilki7 (794)


from PIL import Image
im = Image.open('Saga.jpg')
pixelMap = im.load()

img = Image.new( im.mode, im.size)
pixelsNew = img.load()

for i in range(img.size[0]):
    for j in range(img.size[1]):
        # your code here


Technically pixelsNew is an N by 1 matrix, but it gets you the pixel data which you can then put it in whatever sized matrix you want.

Masy (26)

Exactly what Mwilki Said, that should work, Mark them as the correct answer :)