How to loop all image pixels and tell whether they are black or white

You should be using getpixel rather than using indexing operators. Note that this may be very slow. You would be better off using getdata, which returns all of pixels as a sequence.

See http://effbot.org/imagingbook/image.htm .


Try:

pix = aImage.load()
print pix[x, y]

Also note that you can use tuples as dictionary keys, you can use mydict[(x, y)] instead of mydict["x,y"].

This pixel information is already stored in the image, why store it in a dict?