Normalized crosscorrelation using xcorr, warped image gives higher peaks than self-similar.

2 views (last 30 days)
Hi, I'm processing a ton of images, and due to a problem with ensemble averaging and fitting procedures, I decided to make a pseudo-PIV code that warps images and determines how much the images change over time. However, I found some very strange results, that a normalized xcorr of 2 different images can give a larger correlation peak than a correlation of the same image!
So I decided to test this by simulating a triangle and a gaussian signal, and stretching the gaussian by changing its sigma (or standard deviation). At some point it comes close to the original image (see figure with k=8). This is when the correlation peak should be largest, but instead it increases as you decrease the width. This is incredibly unintuitive and I feel I am missing something.
tl;dr: I am normalizing the functions
supporting images:
What SHOULD be one of the best fits :
Actual highest correlation (increases as you make it thinner.
Changing max correlation peak with the stretch factor
Code:
close all
clear all
x = 1:1:120;
for i = 1:1:120
if i<=40
triangle(i)=0;
else
if i<=60
triangle(i)=3*(i-40);
else
if i<=80
triangle(i)=triangle(60)-3*(i-60);
else
triangle(i)=0;
end
end
end
end
for k=1:12
sigma_x = k;
mu_x = 60;
gaussian(x) = (1/(sigma_x * (2*pi)^0.5)) * exp(-(x-mu_x).^2 / (2*sigma_x^2));
gaussian = gaussian/sum(gaussian(:));
triangle = triangle/sum(triangle(:));
Crossgt(k) = max(xcorr(gaussian,triangle));
Crosstr(k) = max(xcorr(triangle,triangle));
end
figure(1)
plot(triangle)
hold on
plot(gaussian)
figure(2)
plot(Crossgt)
hold on
plot(Crosstr)

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!