# calculate displacement between 2 images

4 views (last 30 days)
emar on 26 Jun 2017
Edited: emar on 26 Jun 2017
Hello,
I would like to ask a question about normalized cross correlation.
Indeed,the steps of calculation of normalized cross correlation (NCC) are :
1. Calculation of FFT or convolution
2. Calculation of local sums
The formula of NCC is available in the bottom of this documentation https://fr.mathworks.com/help/images/ref/normxcorr2.html
In the first step, I took:
a =
0.4693 0.2015 0.3220 0.8843
0.9090 0.1872 0.7254 0.8845
0.6666 0.6917 0.4871 0.3952
0.1845 0.9348 0.2403 0.9641
b =
0.5244 0.0120 0.0678 0.8644
0.4334 0.1436 0.4166 0.7587
0.8684 0.7909 0.5884 0.9340
0.4638 0.0562 0.5183 0.6035
Then
a2 =
0.4693 0.2015 0.3220 0.8843 0 0
0.9090 0.1872 0.7254 0.8845 0 0
0.6666 0.6917 0.4871 0.3952 0 0
0.1845 0.9348 0.2403 0.9641 0 0
0 0 0 0 0 0
0 0 0 0 0 0
b2 =
0.5244 0.0120 0.0678 0.8644 0 0
0.4334 0.1436 0.4166 0.7587 0 0
0.8684 0.7909 0.5884 0.9340 0 0
0.4638 0.0562 0.5183 0.6035 0 0
0 0 0 0 0 0
0 0 0 0 0 0
I found :
conv2(rot90(a,2),b)
ans =
0.5055 0.1376 0.5584 0.9575 0.2733 0.8205 0.1595
0.6250 0.5028 1.2366 1.7782 1.0741 1.4291 0.7161
1.4722 1.6299 2.2702 4.1249 2.3243 2.0076 1.4637
1.6373 1.5220 2.8883 5.0546 3.0854 2.4246 1.8292
1.3345 1.8440 2.3115 4.0665 2.5920 1.8209 1.6073
1.1781 1.3650 1.5358 2.9240 1.3762 1.0484 0.9869
0.4101 0.1990 0.5698 0.9295 0.3251 0.3648 0.2832
conv2(rot90(a2,2),b2)
ans =
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0.5055 0.1376 0.5584 0.9575 0.2733 0.8205 0.1595 0 0
0 0 0.6250 0.5028 1.2366 1.7782 1.0741 1.4291 0.7161 0 0
0 0 1.4722 1.6299 2.2702 4.1249 2.3243 2.0076 1.4637 0 0
0 0 1.6373 1.5220 2.8883 5.0546 3.0854 2.4246 1.8292 0 0
0 0 1.3345 1.8440 2.3115 4.0665 2.5920 1.8209 1.6073 0 0
0 0 1.1781 1.3650 1.5358 2.9240 1.3762 1.0484 0.9869 0 0
0 0 0.4101 0.1990 0.5698 0.9295 0.3251 0.3648 0.2832 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
So, adding zeros will not change the result of FFT /convolution. But after calculating local sums, the result changes because it takes into consideration the size of a (or a2). (normxcorr2(a,b) is different from normxcorr2(a2,b2))
So when I want to calculate the displacement between two grayscale images using cross correlation, the result is not the same than if I translated the image (by padding with zeros)
Could you explain me why the displacement changes even if the translation (padding) is the same?

### Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!