Azzera filtri
Azzera filtri

Cross-corr​elation(xc​orr2) on image matrix

20 visualizzazioni (ultimi 30 giorni)
Pierluigi Valentino
Pierluigi Valentino il 7 Gen 2022
Risposto: Pratyush Roy il 10 Gen 2022
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.

Risposte (1)

Pratyush Roy
Pratyush Roy il 10 Gen 2022
Hi Pierluigi,
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_1 = 7×7
34 201 286 121 106 167 60 165 470 329 244 334 299 109 271 359 405 570 585 479 256 186 229 550 615 730 409 206 116 309 595 760 575 349 221 137 263 504 434 339 222 51 66 119 256 181 256 25 72
corrmat_2 = xcorr2(M2,M1)
corrmat_2 = 7×7
72 25 256 181 256 119 66 51 222 339 434 504 263 137 221 349 575 760 595 309 116 206 409 730 615 550 229 186 256 479 585 570 405 359 271 109 299 334 244 329 470 165 60 167 106 121 286 201 34
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!

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by