title: Calculating covariance between 2 planes with NumPy
body: <p>Suppose we have two frames of a video and we want to return a matrix of the covariance between the two frames. This matrix will have the same dimensions as one of the two frames.</p>
  
  <p>I've simplified my code below. This is part of a class implementation, so much of it wasn't necessary to show. </p>
  
  <pre><code>def covar(self,frame):
  
      return np.cov(current_frame,next_frame)
  </code></pre>
  
  <p>This returns a plane as  I wanted. But the problem with the above is that it returns much larger dimensions. It would help to know how the np.cov returns a value. Any pointers?</p>
  
  <p><strong>Edit</strong>: </p>
  
  <p>I'd like to clarify what I meant. My 2 frames are grayscale images represented by intensity values in a matrix. Each value maps to a pixel. I am trying to find the covariance between a pixel in one frame and the next frame.</p>
  
  <p>(Also, I prefer to use NumPy or other very efficient computational methods as there may be thousands of images in my stack.)</p>
  
  <p><strong>Edit2</strong>: </p>
  
  <p>Suppose I'd like to use OpenCV since NumPy isn't great for image processing. Any tips on using the calcCovarMatrix function (<a href="http://docs.opencv.org/modules/core/doc/operations_on_arrays.html" rel="nofollow">http://docs.opencv.org/modules/core/doc/operations_on_arrays.html</a>)?</p>