Image covariance and mean calculation