Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef unsigned char COLOR;
- struct pixel
- {
- COLOR Blue; //синий
- COLOR Green; //зеленый
- COLOR Red; //красный
- //COLOR Reserved; //резерв
- };
- pixel Med (pixel* mas,int l)
- {
- for (int i=0;i<l;i++)
- for (int j=0;j<l-1;j++) if (mas[j].Blue > mas[j+1].Blue) swap(mas[j],mas[j+1]);
- return mas[l/2];
- }
- void BMPImage::MedianFilter(int** filter,int K)
- {
- pixel** mas = new pixel* [BMPinf.Height];
- for (int c = 0; c < BMPinf.Height; c++)
- mas[c] = new pixel [BMPinf.Width];
- int l=0;
- pixel* buf = new pixel [l];
- int halfk=K/2;
- for(int y=halfk;y<BMPinf.Height-halfk;++y)
- for(int x=halfk;x<BMPinf.Width-halfk;++x)
- {
- for(int u=-halfk;u<=halfk;++u)
- for(int v=-halfk;v<=halfk;++v)
- for (int s=0;s < filter[u+halfk][v+halfk];++s)
- {
- buf[l]=maspixel[y+u][x+v];
- ++l;
- }
- mas[y][x]=Med(buf,l);
- l=0;
- }
- maspixel=mas;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement