PsiLAB Help Manual Page

Section: Correlation of 2 dimensional data

Name: crosscorr_2d_norm

Calculates the 2d normalized and scaled crosscorrelation matrix of two real matrices a and b.

[ c:(float,'b,'c) Matrix.t ] = crosscorr_2d_norm
a:(float,'b,'c) Matrix.t
b:(float,'b,'c) Matrix.t
?c:(float,'b,'c) Matrix.t
()

With the optional c list argument an already allocated result matrix can be given to the function.
The calculation is performed with the Fast Fourier Transform (FFT). Used algorithm method:

G(1) (a,0) = <a*a> (Maximum of Autocorrelation from matrix a)
G(1) (b,0) = <b*b> (Maximum of Autocorrelation from matrix b)
g(1) (a,b, t) = ( G(1) (a,b, t) - (<a>*<b>)) /
( sqrt(<a*a> - <a>)*sqrt(<b*b> - <b>) )

The crosscorrelation matrix G(1) is calculated using the FFT in the following way:

af = FFT (a,Forward)
bf = FFT (b,Foward)
cf = af <*> (conjmat bf)
c = FFT (cf,Backward,Reorder)
c0 = c </> ( Number of matrix elements )

Example:

[] let f = fmatrix ~dim:[500;300] ~rand:[1.0] () ;; 
[] let g = fmatrix ~dim:[500;300] ~rand:[1.0] () ;; 
[] let crossc = crosscorr_2d_norm f g () ;; 
[] crosscorr_2d_norm f g ~c:[crossc] (); 

Printed by PsiLAB