1#ifndef __crossCorrelation_hpp__
2#define __crossCorrelation_hpp__
12template <
typename floatT,
typename sizeT =
size_t>
13void calcDiscreteCrossCorrelation( floatT *cc,
24 sizeT cc_dim1, cc_dim2;
48 cc_dim1 = max_x_lag - min_x_lag + 1;
49 cc_dim2 = max_y_lag - min_y_lag + 1;
52 for( sizeT i = min_x_lag; i < max_x_lag + 1; ++i )
54 for( sizeT j = min_y_lag; j < max_y_lag + 1; ++j )
57 cc[( j - min_y_lag ) * cc_dim1 + ( i - min_x_lag )] = 0;
61 for( sizeT k = 0;
k < dim1; ++
k )
68 for( sizeT l = 0; l < dim2; ++l )
74 cc[( j - min_y_lag ) * cc_dim1 + ( i - min_x_lag )] +=
75 m1[l * dim1 +
k] * m2[( l + j ) * dim1 + ( k + i )];
82template <
class eigenT,
class eigenTin1,
class eigenTin2,
class eigenTmask>
83void xdiscreteCrossCorrelation(
84 eigenT &cc,
const eigenTin1 &m1,
const eigenTin2 &m2, eigenTmask &mask,
int minlag = 0,
int maxlag = 0 )
87 size_t dim1 = m1.rows();
88 size_t dim2 = m2.cols();
90 if( dim1 != m2.rows() || dim2 != m2.cols() || dim1 != mask.rows() || dim2 != mask.cols() )
98 maxlag = std::min( dim1, dim2 );
102 cc.resize( maxlag - minlag + 1, maxlag - minlag + 1 );
104 for(
int i = minlag; i < maxlag + 1; i++ )
106 for(
int j = minlag; j < maxlag + 1; j++ )
108 cc( i - minlag, j - minlag ) = 0;
110 for(
int k = 0;
k < dim1;
k++ )
117 for(
int l = 0; l < dim2; l++ )
123 cc( i - minlag, j - minlag ) +=
124 m1( k, l ) * mask( k, l ) * m2( k + i, l + j ) * mask( k + i, l + j );
131template <
class eigenT,
class eigenTin1,
class eigenTin2>
132void discreteCrossCorrelation(
typename eigenT::Scalar &xlag,
133 typename eigenT::Scalar &ylag,
142 fitGaussian2D<gaussian2D_gen_fitter<float>> fitG;
144 size_t dim1 = m1.rows();
145 size_t dim2 = m1.cols();
147 if( dim1 != m2.rows() || dim2 != m2.cols() )
165 cc.resize( max_x_lag - min_x_lag + 1, max_y_lag - min_y_lag + 1 );
167 calcDiscreteCrossCorrelation<float, int>( (
float *)cc.data(),
177 fitG.setArray( cc.data(), cc.rows(), cc.cols() );
179 typename eigenT::Index row, col;
180 typename eigenT::Scalar maxval;
181 maxval = cc.maxCoeff( &row, &col );
185 fitG.setGuess( 0., 1., row, col, 4., 4., 0. );
190 xlag = min_x_lag + fitG.get_params()[2];
191 ylag = min_y_lag + fitG.get_params()[3];
constexpr units::realT k()
Boltzmann Constant.