Guest User

Untitled

a guest
Jun 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. void Correlation( IplImage *LeftImage, IplImage *RightImage, int WindowSize, int x, int y ) {
  2.   dmPixel LeftPixel;
  3.   dmPixel RightPixel;
  4.   int j, i, dx, dj, di;
  5.   int WindowHalf = ( WindowSize - 1 ) / 2;
  6.   float numerator, denominator[2], result;
  7.   int LAverageWindowBrightness, RAverageWindowBrightness;
  8.  
  9.   for( j = y - WindowHalf; j <= y + WindowHalf; j++ ) {
  10.     for( i = x - WindowHalf; i <= x + WindowHalf; i++ ) {
  11.       LAverageWindowBrightness += DM_BRIGHTNESS( GetPixel( LeftImage->imageData, LeftImage->widthStep, i, j ) );
  12.     }
  13.   }
  14.   LAverageWindowBrightness /= WindowSize * WindowSize;
  15.   LeftPixel = GetPixel( LeftImage->imageData, LeftImage->widthStep, x, y );
  16.  
  17.   for( j = y - WindowHalf; j <= y + WindowHalf; j++ ) {
  18.     for( i = x - WindowHalf; i <= x + WindowHalf; i++ ) {
  19.      
  20.       RightPixel = GetPixel( RightImage->imageData, LeftImage->widthStep, x + i, y + j );
  21.       for( dj = j - WindowHalf; dj <= j + WindowHalf; dj++ ) {
  22.         for( di = i - WindowHalf; di <= i + WindowHalf; di++ ) {
  23.           RAverageWindowBrightness += DM_BRIGHTNESS( GetPixel( RightImage->imageData, RightImage->widthStep, i, j ) );
  24.         }
  25.       }
  26.       RAverageWindowBrightness /= WindowSize * WindowSize;
  27.  
  28.       numerator += pow( ( DM_BRIGHTNESS( LeftPixel ) - LAverageWindowBrightness ) - ( DM_BRIGHTNESS( RightPixel ) - RAverageWindowBrightness ), 2.0f );
  29.       denominator[0] += pow( ( DM_BRIGHTNESS( LeftPixel ) - LAverageWindowBrightness ), 2.0f );
  30.       denominator[1] += pow( ( DM_BRIGHTNESS( RightPixel ) - RAverageWindowBrightness ), 2.0f );
  31.     }
  32.   }
  33.   result = numerator / ( denominator[0] * denominator[1] );
  34. }
Add Comment
Please, Sign In to add comment