Cross-correlation(xcorr2) on image matrix
7 views (last 30 days)
Hi,hope someone can help me.
I've a problem with xcorr2 function.I've to correlate two matrix (a 32*32 pixel of an image for a piv method) in order to find a correlation peak.
I obtain different result if I execute xcorr2(ima,imb) and xcorr2(imb,ima).
How is it possible? The procudere should not be commutative?
Thanks in advance.
Pratyush Roy on 10 Jan 2022
2D cross-correlation is not a commutative operation unlike 2D convolution which is a commutative operation.
The example below illustrates how the 2D cross correlation between M1 and M2 is different from that between M2 and M1:
M1 = [17 24 1 8 15;
23 5 7 14 16;
4 6 13 20 22;
10 12 19 21 3;
11 18 25 2 9];
M2 = [8 1 6;
3 5 7;
4 9 2];
corrmat_1 = xcorr2(M1,M2)
corrmat_2 = xcorr2(M2,M1)
if we run this command, correlation matrix corrmat_1 is computed by keeping M1 fixed while moving M2 from left to right in a row then striding down and again repeating the process. Hence the first element of the matrix turns out to be 17(M1(1,1)) multiplied by 2(M2(3,3)) which is 34.
On the other hand, correlation matrix corrmat_2 is computed by keeping M2 fixed while moving M1.Hence the first element of the matrix turns out to be 8(M2(1,1)) multiplied by 9(M1(5,5)) which is 72.
The doc link for xcorr2 might be helpful for gaining more information on this.
Hope this helps!