public unsafe Bitmap MedianFilter(Bitmap Img) { int Size =2; List<byte> R = new List<byte>(); List<byte> G = new List<byte>(); List<byte> B = new List<byte>(); int ApetureMin = -(Size / 2); int ApetureMax = (Size / 2); BitmapData imageData = Img.LockBits(new Rectangle(0, 0, Img.Width, Img.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb); byte* start = (byte*)imageData.Scan0.ToPointer (); for (int x = 0; x < imageData.Width; x++) { for (int y = 0; y < imageData.Height; y++) { for (int x1 = ApetureMin; x1 < ApetureMax; x1++) { int valx = x + x1; if (valx >= 0 && valx < imageData.Width) { for (int y1 = ApetureMin; y1 < ApetureMax; y1++) { int valy = y + y1; if (valy >= 0 && valy < imageData.Height) { // error come from here Color tempColor = Img.GetPixel(valx, valy); R.Add(tempColor.R); G.Add(tempColor.G); B.Add(tempColor.B); } } } } } } R.Sort(); G.Sort(); B.Sort(); Img.UnlockBits(imageData); return Img; }
GetPixel
SetPixel
LockBits
UnlockBits
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)