c#指针进行图像操作
2009-06-08 08:32:21 来源:WEB开发网比较GDI+使用的GetPixel/SetPixel,让你立马感到这个世界多么美妙
再来一个中值滤波的操作
1 /// <summary>
2 /// 中值滤波
3 /// </summary>
4 /// <param name="dgGrayValue"></param>
5 public void MedianFilter(int dgGrayValue)
6 {
7 // 100M 双线空间 + 50M数据库 28元/年
8 // 1G 双线空间 + 200M数据库 100元/年
9 // QQ:70975363
10 byte s;
11 byte[] p = new byte[9];
12 int i, j;
13 int x, y;
14 int Stride;
15 unsafe
16 {
17 byte* point = (byte*)this.ImageData.Scan0;
18 Stride = this.ImageData.Stride;
19 point = point + 3 + this.ImageData.Stride;
20 for (i = 0; i < this.ImageData.Height - 1; i++)
21 {
22 for (j = 0; j < this.ImageData.Width - 1; j++)
23 {
24 p[0] = *(point - Stride - 1);
25 p[1] = *(point - Stride + 2);
26 p[2] = *(point - Stride + 5);
27 p[3] = *(point - 1);
28 p[4] = *(point + 2);
29 p[5] = *(point + 5);
30 p[6] = *(point + Stride - 1);
31 p[7] = *(point + Stride + 2);
32 p[8] = *(point + Stride + 5);
33 for (x = 0; x < 5; x++)
34 {
35 for (y = x + 1; y < 9; y++)
36 {
37 if (p[x] > p[y])
38 {
39 s = p[x];
40 p[x] = p[y];
41 p[y] = s;
42 }
43 }
44 }
45 *point = p[4];
46 *(point - 1) = p[4];
47 *(point - 2) = p[4];
48 point += 3;
49
50 }
51 point += Stride - this.ImageData.Width * 3;
52 }
53 }
54 }
55
更多精彩
赞助商链接