Image covariance

Hello, i would like to ask you how can i calculate the covariance of an image without using thrust or Cublas library of cuda and thank you all have a nice day.