I have a simple black and white only gif image (400x400px let's say).
I need to get all pixels from that image and find whether they are black or white. I need to create a dictionary with the information about the pixels and their colors then.
I'm pretty new to python so I am kinda struggling with this. But here goes my script so far:
#!/usr/bin/env python
import os
import Image
os.chdir("D:/python-projects")
aImage = Image.open("input.gif")
aPixelsBlackOrWhiteDictionary = {}
# now I need to fill the dictionary with values such as
# "X,Y": 0
# "X,Y": 1
# where X,Y are coordinates and 0/1 i the pixel color (b/w)
Basically I want the final dictionary to be something like this:
"0,0" : 0 # pixel with X=0,Y=0 coordinates is black
"1,0" : 1 # pixel with X=1,Y=0 coordinates is White
EDIT:
When I try:
print aImage[0, 0]
I get an error:
Traceback (most recent call last):
File "D:\python-projects\backprop.py", line 15, in <module>
print aImage[0, 0]
File "C:\Python26\lib\site-packages\pil-1.1.7-py2.6-win32.egg\Image.py", line
512, in __getattr__
raise AttributeError(name)
AttributeError: __getitem__