Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Correlation( IplImage *LeftImage, IplImage *RightImage, int WindowSize, int x, int y ) {
- dmPixel LeftPixel;
- dmPixel RightPixel;
- int j, i, dx, dj, di;
- int WindowHalf = ( WindowSize - 1 ) / 2;
- float numerator, denominator[2], result;
- int LAverageWindowBrightness, RAverageWindowBrightness;
- for( j = y - WindowHalf; j <= y + WindowHalf; j++ ) {
- for( i = x - WindowHalf; i <= x + WindowHalf; i++ ) {
- LAverageWindowBrightness += DM_BRIGHTNESS( GetPixel( LeftImage->imageData, LeftImage->widthStep, i, j ) );
- }
- }
- LAverageWindowBrightness /= WindowSize * WindowSize;
- LeftPixel = GetPixel( LeftImage->imageData, LeftImage->widthStep, x, y );
- for( j = y - WindowHalf; j <= y + WindowHalf; j++ ) {
- for( i = x - WindowHalf; i <= x + WindowHalf; i++ ) {
- RightPixel = GetPixel( RightImage->imageData, LeftImage->widthStep, x + i, y + j );
- for( dj = j - WindowHalf; dj <= j + WindowHalf; dj++ ) {
- for( di = i - WindowHalf; di <= i + WindowHalf; di++ ) {
- RAverageWindowBrightness += DM_BRIGHTNESS( GetPixel( RightImage->imageData, RightImage->widthStep, i, j ) );
- }
- }
- RAverageWindowBrightness /= WindowSize * WindowSize;
- numerator += pow( ( DM_BRIGHTNESS( LeftPixel ) - LAverageWindowBrightness ) - ( DM_BRIGHTNESS( RightPixel ) - RAverageWindowBrightness ), 2.0f );
- denominator[0] += pow( ( DM_BRIGHTNESS( LeftPixel ) - LAverageWindowBrightness ), 2.0f );
- denominator[1] += pow( ( DM_BRIGHTNESS( RightPixel ) - RAverageWindowBrightness ), 2.0f );
- }
- }
- result = numerator / ( denominator[0] * denominator[1] );
- }
Add Comment
Please, Sign In to add comment