title: Images opened in Pillow and OpenCV are not equivelant
body: <p>I downloaded a test image from Wikipedia (the tree seen below) to compare <code>Pillow</code> and <code>OpenCV</code> (using <code>cv2</code>) in python. Perceptually the two images appear the same, but their respective <code>md5</code> hashes don't match; and if I subtract the two images the result is not even close to solid black (the image shown below the original). The original image is a JPEG. If I convert it to a PNG first, the hashes match.</p>
  
  <p>The last image shows the frequency distribution of how the pixel value differences.</p>
  
  <p>As Catree pointed out my subtraction was causing integer overflow. I updated to converting too <code>dtype=int</code> before the subtraction (to show the negative values) and then taking the absolute value before plotting the difference. Now the difference image is perceptually solid black.</p>
  
  <p>This is the code I used:</p>
  
  <pre><code>from PIL import Image
  import cv2
  import sys
  import md5
  import numpy as np
  
  def hashIm(im):
      imP = np.array(Image.open(im))
  
      # Convert to BGR and drop alpha channel if it exists
      imP = imP[..., 2::-1]
      # Make the array contiguous again
      imP = np.array(imP)
      im = cv2.imread(im)
  
      diff = im.astype(int)-imP.astype(int)
  
      cv2.imshow('cv2', im)
      cv2.imshow('PIL', imP)
      cv2.imshow('diff', np.abs(diff).astype(np.uint8))
      cv2.imshow('diff_overflow', diff.astype(np.uint8))
  
      with open('dist.csv', 'w') as outfile:
          diff = im-imP
          for i in range(-256, 256):
              outfile.write('{},{}\n'.format(i, np.count_nonzero(diff==i)))
  
      cv2.waitKey(0)
      cv2.destroyAllWindows()
  
      return md5.md5(im).hexdigest() + '   ' + md5.md5(imP).hexdigest()
  
  if __name__ == '__main__':
      print sys.argv[1] + '\t' + hashIm(sys.argv[1])
  </code></pre>
  
  <hr>
  
  <p><a href="https://i.stack.imgur.com/iWUnD.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iWUnD.jpg" alt="Original photo of a tree (from Wikipedia &quot;Tree&quot; article)"></a></p>
  
  <p>Frequency distribution updated to show negative values.</p>
  
  <p><a href="https://i.stack.imgur.com/sHTQk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sHTQk.png" alt="Updated difference"></a></p>
  
  <hr>
  
  <p>This is what I was seeing before I implemented the changes recommended by Catree.</p>
  
  <p><a href="https://i.stack.imgur.com/UNNtB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UNNtB.png" alt="Difference"></a></p>
  
  <p><a href="https://i.stack.imgur.com/m5zdS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m5zdS.png" alt="Dist"></a></p>