MATLAB: How to calculate correlation coefficients for each corresponding pixel of two images(of same dimensions)? I need the output also to be of same dimension.

computer visionimage processingmachine learning

I am trying to implement a paper titled "Detection of microaneurysms using multi-scale correlation coefficients ".
In that, we are supposed to extract green channel image from rgb retinal image [ fig 7(a) ] and apply a gaussian filter with five different sigma values(1.1,1.2,1.3,1.4,1.5) to the green chanel image to get 5 corresponding gaussian blur images.Now,we have one original image and 5 gaussian blur images.
Now,Correlation coeffient of the green channel image and each of the five blur images is calculated pixel wise to get five corresponding matrices.
The maximum response for each corresponding pixel in the five output matrices values will be selected and a new matrix is formed with them.This new matrix is the final output matrix [ fig7(b) ].
i have tried using all correlation functions like corr2,corrcoeff but of no use since i want an output matrix of same dimensions as input images.
The input and output should look like this:
Can someone give any insights on how to compute correlation coeffients for each pixel to get the required output?
This is the first step mentioned in paper: "The first step in coarse level candidate detection involves applying a sliding neighborhood filter with multi-scale Gaussian kernels to the fundus image in order to calculate a correlation coefficient for each pixel."
Thank you.

Best Answer

  • I believe they used a slided window cross correlation, which is basically the same as if you use corr2 (which will give you just one value) in all possible overlaping combinations of the two images, which would force you to pad one of them, so the dimensions would always be right. This is basically the same as the function normxcorr2 does. So you can use it in the two images and then remove the added pad, so you end up with same dimensions. Here's an example for a random image, where the auto correlation coefficient is expected to be 1 when the images exactly meet (at the center) and close to 0 elsewhere:
    A = randn(7);
    C = normxcorr2 (A,A);
    ExtraPad = (length(A)-1)/2+1;
    C = C(ExtraPad:end-ExtraPad+1,ExtraPad:end-ExtraPad+1);