1. 程式人生 > >高斯濾波 邊界優化處理

高斯濾波 邊界優化處理

for ebo 後來 b+ sharp ant 直接 har highlight

接上一篇高斯濾波,後來測試發現,與其擴充邊界(費力氣)處理,不如直接把之設為0(效果好):

List<Point> pointL = new List<Point>();
        private void myGaussFilter123(short[,] data)
        {
            int w_Data = data.GetLength(0);
            int h_Data = data.GetLength(1);
            double[,] arr = gaussFilter(3, 1.5);
            for (int i = 2; i < w_Data - 1; i++)
            {
                for (int j = 2; j < h_Data - 1; j++)
                {
                    bool judgeBool = false;
                    for (int a = i - 1; a <= i + 1; a++)
                    {
                        for (int b = j - 1; b <= j + 1; b++)
                        {
                            if (Math.Abs(a - i) == 1 || Math.Abs(b - j) == 1)
                            {
                                if (data[a, b] == 0)
                                {
                                    judgeBool = true;
                                    break;
                                }
                            }
                        }
                        if (judgeBool)
                        {
                            break;
                        }
                    }
                    if (judgeBool)
                    {
                        if (data[i, j] > 0)
                        {
                            short[,] shortTmp = (short[,])data.Clone();
                            pointL.Add(new Point(i,j));
                            //data[i, j] = edgeBianTong(shortTmp, new Point(i, j), arr);
                        }
                        continue;
                    }
                    double tmpValue = 0;
                    for (int x = 0; x < 3; x++)
                    {
                        for (int y = 0; y < 3; y++)
                        {
                            tmpValue += data[i + 1 - x, j + 1 - y] * arr[x, y];//高斯濾波矩陣是對稱的

                        }
                    }
                    data[i, j] = (short)tmpValue;
                }
            }

            foreach (Point point in pointL)
            {
                data[point.X, point.Y] = 0;
            }
        }

高斯濾波 邊界優化處理