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$
2
  • $\begingroup$ You can use something like np.cov(x,y)[0,1] $\endgroup$
    – PedroSebe
    Oct 18 '20 at 2:06
  • $\begingroup$ I don't get a 2x2 matrix though, when I do np.cov(x,y) $\endgroup$ Oct 18 '20 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)$

$\endgroup$
2
  • $\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 '20 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$ Oct 19 '20 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.