1
$\begingroup$

I am trying to implement SSIM Structural similarity in Python.

One of the necessary elements is the covariance between the two matrices. Using numpy.cov() We get a covariance matrix.

Is there a way to go from the covariance matrix to a single value representing the covariance?

$\endgroup$
  • $\begingroup$ You can use something like np.cov(x,y)[0,1] $\endgroup$ – PedroSebe Oct 18 at 2:06
  • $\begingroup$ I don't get a 2x2 matrix though, when I do np.cov(x,y) $\endgroup$ – pellucidcoder Oct 18 at 3:12
1
$\begingroup$

The original paper (link) gives the covariance calculation as

$\sigma_{xy} = \frac{1}{N-1}\Sigma_{i=1}^N(x_i - \mu_x)(y_i - \mu_y)$

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Where are the "two matrices" in this formula? This is just the standard formula for a covariance estimate for paired data. $\endgroup$ – whuber Oct 18 at 15:55
  • $\begingroup$ I believe in the paper x and y are the matrices. N is the number of elements in the matrix. x_i is the ith element in the matrix...so I guess there is a bit of liberty taken with the notation $\endgroup$ – pellucidcoder Oct 19 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.