Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correlation among 2 images

I am trying to find the following correlation among two images f1 and f2 where the size of the image is PXP.

I have written a for loop program for the same but I think an inbuilt function would be faster for the same.

enter image description here

Which function in matlab can help me compute this ?

Also if the size of both the images are M X N can someone tell me how this formula will change or if the function will be able to handle it.

EDIT:

Is there any faster function than xcorr2 that can help me seeing that it takes too much time when I only need to have the value for correlation the unshifted images....

like image 372
user671805 Avatar asked Nov 29 '22 13:11

user671805


2 Answers

This is the function used to do correlation (coefficient) between two images (matrices):

r = corr2(A,B) computes the correlation coefficient between A and B, where A and B are matrices or vectors of the same size.

while xcorr2 (A, B) solves for CROSS correlation.

like image 195
The Byzantine Avatar answered Dec 04 '22 07:12

The Byzantine


MATLAB has xcorr2 just for this purpose. I suppose your code would look something like:

r = xcorr2(f1, f2) / (P .^ 2)

Where f1 and f2 are the two images. The resulting matrix r is a (2P-1)×(2P-1) matrix, and each of its elements reflect the measure of similarity between f1 and f2, when the two images are shifted by an offset corresponding to that element's offset from the center.

Note that if you're interested only in the correlation between two unshifted images, then you should save execution time and use corr2, like @TheByzantine has suggested in his answer.

like image 25
Eitan T Avatar answered Dec 04 '22 08:12

Eitan T