Question

I have a gray scale image stored in a matrix Mat and am asked to extract the covariances for 1 pixel horizontal and vertical displacement.

I thought of using circshift and cov to extract the covariance.

Mat = magic(5); % this represents my gray scale image
MatHs = circshift(Mat,[0 1]); % horizontal displacement
MatVs = circshift(Mat,[1 0]); % vertical displacement

covMatH = cov(Mat,MatHs)
covMatV = cov(Mat,MatVs)

However, the result of covMatH and covMatV must be of size 1 by 1 where mine is 2 by 2. Did I misapplied the cov functions or have I not understood the question correctly and this task must be solved completely different?

Was it helpful?

Solution

Since your image is 2-dimensional, you will be receiving a covariance matrix (link) of size 2*2. You have definitely solved the task of finding the covariance, but each element of the 2*2 matrix represents a different index. Lets say the matrix is [A B; C D]. A and D would represent variance of the inputs. B and C would represent cross-covariance between the inputs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top