title: distance between all pixels of two images
body: <p>I'm using python and opencv and a custom distance function <code>dist()</code> to calculate the distance between one main image and three test images.
  The final image that is returned is <code>min(distance1, distance2, distance3)</code>
  I'm currently going over both the axes of the images using a for loop and calculating the distance. This way it is very slow, as the for loops are slow. Is there any pythonic way to do this?</p>
  
  <p>Each pixel of each image has two values (mu, sigma)</p>
  
  <p>distance function that is used: </p>
  
  <pre><code>def w2distance2D(mu1, sig1, mu2, sig2):
      """
  
      Returns the Wasserstein distance between two 2-Dimensional normal distributions
  
      """
      t1 = np.linalg.norm(mu1 - mu2)
  
      #print t1
      t1 = t1 ** 2.0
      #print t1
      t2 = np.trace(sig2) + np.trace(sig1) 
      p1 = np.trace(np.dot(sig1, sig2))
      p2 =  (((np.linalg.det(np.dot(sig1, sig2)))))
      if p2 &lt; 0.0:
          p2 = 0.0
      p2 = np.sqrt(p2)
      tt = p1 + 2.0*p2
      if tt &lt; 0.0:
          tt = 0.0
      t3 = 2.0 * np.sqrt(tt)
      #print t3
      if (t1 + t2 - t3) &lt; 0:
          result = 0.0
          #print "here"
      else:
          result = np.sqrt(t1 + t2 - t3)
  
      return result
  </code></pre>