title: How to loop all image pixels and tell whether they are black or white
body: <p>I have a simple black and white only gif image (400x400px let's say).</p>
  
  <p>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.</p>
  
  <p>I'm pretty new to python so I am kinda struggling with this. But here goes my script so far:</p>
  
  <pre><code>#!/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)
  </code></pre>
  
  <p>Basically I want the final dictionary to be something like this:</p>
  
  <pre><code>"0,0" : 0 # pixel with X=0,Y=0 coordinates is black
  "1,0" : 1 # pixel with X=1,Y=0 coordinates is White
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>When I try:</p>
  
  <pre><code>print aImage[0, 0]
  </code></pre>
  
  <p>I get an error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "D:\python-projects\backprop.py", line 15, in &lt;module&gt;
      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__
  </code></pre>