title: int' object has no attribute '__getitem__'
body: <p>I am a beginner in python and am trying to find similarity between images by testing against a test_pic and a database containing images.  I have passed images from a directory and compared it using SIFT features</p>
  
  <pre><code>from PIL import Image
  from PIL import ImageStat
  from PIL import ImageFilter
  import os
  
  def get_imlist(path):
      """    Returns a list of filenames for 
          all jpg images in a directory. """
  
      return [os.path.join(f) for f in os.listdir(path) if f.endswith('.png')]
  
  def fe(file_name):
      im = Image.open(file_name)
      im = im.convert('L')
      w, h = 300, 300
      im = im.resize((w, h))
      imst = ImageStat.Stat(im)
      sr = imst.mean[0]
      def foo(t):
          if t &lt; sr * 2 / 3: return 0
          if t &lt;= sr: return 1
          if t &lt; sr * 4 / 3: return 2
          return 3
      im = im.point(foo)
      res = [[0] * 4 for i in range(10)]
      for y in range(h):
          for x in range(w):
              k = im.getpixel((x, y))
              res[y / 60][k] += 1
              res[x / 60 + 5][k] += 1
      return res
  
  def ff(file_name):
      im = Image.open(file_name)
      im = im.convert('L')
      w, h = 300, 300
      im = im.resize((w, h))
      im = im.filter(ImageFilter.FIND_EDGES)
      sr = ImageStat.Stat(im).mean[0]
      res = 0
      for i in range(h):
          for j in range(w):
              if im.getpixel((j, i)) &gt; sr:
                  res += 1
      #im.show()
      return res
  
  test_pic = '128.png' #testing this pic against all pics in our db;
  path='D:/ex'
  imlist=[]
  db=[]
  imlist=get_imlist(path)
  for file in imlist:
      x = [0, file]
      db.append(x)  
  z = [fe(db[i][1]) for i in range(len(db))]
  test_z = fe(test_pic)
  for k in range(len(db)):
      for i in range(10):
          for j in range(4):
              db[k][0] += abs(z[k][i][j] - test_z[i][j])
  db.sort()
  
  print
  print '1st-line sifting [by fe()]'
  print '--------------------'
  print test_pic
  print '--------------------'
  for k in range(len(db)):
      if db[k][0] &lt; 20 * 3600:
          print '%12s %7.2f' % (db[k][1], db[k][0] / 3600.0,)
      else:
          break
  print '--------------------'
  print
  print
  print '2nd-line sifting [by ff()]'
  print '--------------------'
  print test_pic
  print '--------------------'
  test_t = ff(test_pic)
  for k in range(len(db)):
      if db[k][0] &lt; 5 * 3600:
          print '%12s' % (db[k][1],)
      elif db[k][0] &lt; 20 * 3600:
          t = ff(db[k][1])
          if abs(t - test_t) * 200.0 / (t + test_t) &lt; 20:
              print '%12s' % (db[k][1],)
      else:
          break
  print '--------------------'
  
  raw_input('\nPress...\n')
  </code></pre>