title: Comparing two images/pictures, and mark the difference
body: <p>I am learning to compare two images/pictures. I found the post <a href="https://stackoverflow.com/questions/1927660/compare-two-images-the-python-linux-way">Compare two images the python/linux way</a> is very useful and I have some questions regarding the technique.</p>
  
  <p>Question 1:</p>
  
  <p>The post shows ways to compare 2 pictures/images. Probably the easiest way is:</p>
  
  <pre><code>from PIL import Image
  from PIL import ImageChops
  
  im1 = Image.open("file1.jpg")
  im2 = Image.open("file2.jpg")
  
  diff = ImageChops.difference(im2, im1).getbbox()
  
  print diff
  </code></pre>
  
  <p>when I have 2 look alike pictures and run above, it give result:</p>
  
  <pre><code>(389, 415, 394, 420)
  </code></pre>
  
  <p>It’s the position on the picture where the difference in 2 pictures lies. So my question is, would it be possible to mark the difference on the picture (for example, draw a circle)?</p>
  
  <p>Question 2:</p>
  
  <pre><code>import math, operator
  from PIL import Image
  def compare(file1, file2):
      image1 = Image.open(file1)
      image2 = Image.open(file2)
      h1 = Image.open("image1").histogram()
      h2 = Image.open("image2").histogram()
  
      rms = math.sqrt(reduce(operator.add, map(lambda a,b: (a-b)**2, h1, h2))/len(h1))
  
  if __name__=='__main__':
      import sys
      file1 = ('c:\\a.jpg')        # added line
      file2 = ('c:\\b.jpg')        # added line
  
      file1, file2 = sys.argv[1:]
      print compare(file1, file2)
  </code></pre>
  
  <p>When I run above, it gives an error “ValueError: need more than 0 values to unpack”, and the problem lies in this line:</p>
  
  <pre><code>file1, file2 = sys.argv[1:]
  </code></pre>
  
  <p>How can I have it corrected? and I tried below it neither works.</p>
  
  <pre><code>    print compare('c:\\a.jpg', 'c:\\b.jpg')
  </code></pre>
  
  <h2>Update</h2>
  
  <p>Added question following Matt's help.</p>
  
  <p>It can draw a rectangle to mark the difference on the two images/pictures. When the two images/pictures looked general the same but there are small spots differences spread. It draws a big rectangle marking the big area include all the spots differences. Is there a way to identically mark the differences individually?</p>