Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. pixel Med (pixel* mas,int l)
  2. {                            
  3.         for (int i=0;i<l;i++)            
  4.                 for (int j=0;j<l-1;j++) if (mas[j].Blue > mas[j+1].Blue) swap(mas[j],mas[j+1]);
  5.     return mas[l/2];
  6. }
  7.  
  8.  
  9. void BMPImage::MedianFilter(int** filter,int K)
  10. {  
  11.     pixel** mas = new pixel* [BMPinf.Height];
  12.     for (int c = 0; c < BMPinf.Height; c++)
  13.         mas[c] = new pixel [BMPinf.Width];
  14.     int l=0;
  15.     pixel* buf = new pixel [l];
  16.     int halfk=K/2;
  17.     for(int y=halfk;y<BMPinf.Height-halfk;++y)
  18.         for(int x=halfk;x<BMPinf.Width-halfk;++x)
  19.         {
  20.             for(int u=-halfk;u<=halfk;++u)
  21.                 for(int v=-halfk;v<=halfk;++v)
  22.                     for (int s=0;s < filter[u+halfk][v+halfk];++s)
  23.                     {
  24.                         buf[l]=maspixel[y+u][x+v];
  25.                         ++l;
  26.                     }
  27.             mas[y][x]=Med(buf,l);
  28.             l=0;
  29.         }
  30.         maspixel=mas;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement