Safiron

Untitled

May 4th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1.     const int no_iteration = 20;
  2.     const float rho = 0.15;
  3.     const float lambda = 0.1;
  4.     float Conductance(int y, int x, int ty, int tx);  
  5.  
  6.  for (int i = 0; i < no_iteration; i++)
  7.     {
  8.         for(int y = 1; y < src->rows - 1; y++)
  9.         {
  10.             for(int x = 1; x < src->cols - 1; x++)
  11.             {
  12.                 float a, b, c, d, e;
  13.                 a = AnisotropicDiffusion::Conductance(y, x, -1, 0);
  14.                 b = AnisotropicDiffusion::Conductance(y, x, 1, 0);
  15.                 c = AnisotropicDiffusion::Conductance(y, x, 0, -1);
  16.                 d = AnisotropicDiffusion::Conductance(y, x, 0, 1);
  17.                 e = a + b + c + d;
  18.                 output.at<float>(y,x) = output.at<float>(y,x) + lambda *(e);
  19.             }
  20.         }
  21.     }
  22.  
  23.  
  24. float AnisotropicDiffusion::Conductance(int y, int x, int ty, int tx)
  25. {
  26.     float a = output.at<float>(y + ty, x + tx);
  27.     float b = output.at<float>(y, x);
  28.     float c = abs(a - b);
  29.     float d = powf(c,2) / powf(rho, 2);
  30.     float e = exp(-d);
  31.     float f = e*(output.at<float>(y+ty, x+tx) - output.at<float>(y,x));
  32.    
  33.     return f;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment