How to find cells corresponding to zero lag in an autocorrelation function

6 views (last 30 days)
Olalekan Ajayi on 4 Sep 2019
Commented: Ajay Pattassery on 19 Sep 2019
Hi,
I am looking to identify the cells corresponding to zero lag for an autocorrelation function. To do that I wrote the following as input:
acf = autocorr2d(I);
[M,N]=size(acf);
lag_x = [1:N]'-ceil((N+1)/2);
lag_y = [1:M]'-ceil((M+1)/2);
[r_0,c_0] = find_r0c0(acf, lag_x,lag_y);
The response I keep getting is: undefined function or variable find_r0c0. How can this be done?
KALYAN ACHARJYA on 4 Sep 2019
Edited: KALYAN ACHARJYA on 4 Sep 2019
May be ?
acf = autocorr2d(I);
[M,N]=size(acf);
lag_x = [1:N]'-ceil((N+1)/2);
lag_y = [1:M]'-ceil((M+1)/2);
[r_0,c_0] = find(acf,lag_x,lag_y);
%..................still ^^ seems issue here

Ajay Pattassery on 18 Sep 2019
Edited: Ajay Pattassery on 18 Sep 2019
The zero lag produces the highest value in the autocorrelation output. Hence simply finding the maximum value of the autocorrelation matrix and finding its coordinates gives the pixel location.
In the below example xcorr2 functions compute the 2-D autocorrelation.
acf = xcorr2(I);
maximum = max(max(acf));
[r_0,c_0]=find(acf==maximum);
Also, the following code will work since the maximum value of the autocorrelation output will be at the middle position.
[m,n] = size(I);
r_0 = ceil((m+n-1)/2);
c_0 = ceil((m+n-1)/2);
Refer the following link for further information on xcorr2.
Ajay Pattassery on 19 Sep 2019
My Pleasure!