Ask coding questions

← Back to all posts
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.

mwilki7 (743)


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

img = 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 :)