title: percentage difference between two images in python using correlation coefficient
body: <p>I want to compare two image chunks such that if they are exactly the same, the result must be 1, and if they match 60 percent, the answer must be 0.6.</p>
  
  <p>In Matlab, I can do this using <code>corr2</code> command, but in python I couldn't find a way. I have tried <code>numpy.corrcoef</code> but it returns a matrix and <code>scipy.signal.correlate2d</code> returns the same. </p>
  
  <p>This is what I have tried:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  from skimage.filter import threshold_otsu
  import matplotlib.cm as cm
  import Image
  import scipy
  from PIL import Image as im
  fname = 'testi.jpg'
  image = Image.open(fname).convert("L")
  arr = np.asarray(image)
  global_thresh = threshold_otsu(arr)
  
  global_otsu = arr &gt;= global_thresh
  global_otsu = np.invert(global_otsu).astype(int)
  a1 = global_otsu[80:150,1350:1350+160]
  fname1 = 'testi2.jpg'
  image1 = Image.open(fname1).convert("L")
  arr1 = np.asarray(image1)
  global_thresh1 = threshold_otsu(arr1)
  
  global_otsu1 = arr1 &gt;= global_thresh1
  global_otsu1 = np.invert(global_otsu1).astype(int)
  a2 = global_otsu1[80:150,1350:1350+160]
  
  co = scipy.signal.correlate2d(a1,a2)
  
  plt.gray()
  plt.subplot(121)
  plt.imshow(a1)
  plt.subplot(122)
  plt.imshow(a2)
  
  plt.show()
  </code></pre>
  
  <p>and the result is:</p>
  
  <pre><code>[[0 0 0 ..., 0 0 0]
  [0 0 0 ..., 0 0 0]
  [0 0 0 ..., 0 0 0]
  ..., 
  [0 0 0 ..., 0 0 0]
  [0 0 0 ..., 0 0 0]
  [0 0 0 ..., 0 0 0]]
  </code></pre>
  
  <p>These are the images that I want to compare:</p>
  
  <p><a href="https://i.stack.imgur.com/bow8D.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bow8D.png" alt="images that i want to compare"></a></p>