Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. typedef unsigned char  COLOR;
  2.  
  3. struct pixel
  4. {
  5.     COLOR   Blue;           //синий
  6.     COLOR   Green;          //зеленый
  7.     COLOR   Red;            //красный
  8.     //COLOR   Reserved;     //резерв
  9. };
  10.  
  11. pixel Med (pixel* mas,int l)
  12. {                            
  13.         for (int i=0;i<l;i++)            
  14.                 for (int j=0;j<l-1;j++) if (mas[j].Blue > mas[j+1].Blue) swap(mas[j],mas[j+1]);
  15.     return mas[l/2];
  16. }
  17.  
  18.  
  19. void BMPImage::MedianFilter(int** filter,int K)
  20. {  
  21.     pixel** mas = new pixel* [BMPinf.Height];
  22.     for (int c = 0; c < BMPinf.Height; c++)
  23.         mas[c] = new pixel [BMPinf.Width];
  24.     int l=0;
  25.     pixel* buf = new pixel [l];
  26.     int halfk=K/2;
  27.     for(int y=halfk;y<BMPinf.Height-halfk;++y)
  28.         for(int x=halfk;x<BMPinf.Width-halfk;++x)
  29.         {
  30.             for(int u=-halfk;u<=halfk;++u)
  31.                 for(int v=-halfk;v<=halfk;++v)
  32.                     for (int s=0;s < filter[u+halfk][v+halfk];++s)
  33.                     {
  34.                         buf[l]=maspixel[y+u][x+v];
  35.                         ++l;
  36.                     }
  37.             mas[y][x]=Med(buf,l);
  38.             l=0;
  39.         }
  40.         maspixel=mas;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement