高斯滤波 边界优化处理

接上一篇高斯滤波,后来测试发现,与其扩充边界(费力气)处理,不如直接把之设为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;
            }
        }

 

posted @ 2018-08-31 18:15  风影我爱罗  阅读(452)  评论(0编辑  收藏  举报