C#高斯平滑算法 :二维高斯卷积代码实例

news/2024/7/21 3:56:48 标签: 算法, c#, 图像处理
 		//高斯平滑处理方法
        //inputImage 输入图像
        // outputImage 输出图像
        //sigema 均方差
        private void gaussSmooth(double[]inputImage,out double[] outputImage,double sigema)
        {
            //方差
            double std2 = 2 * sigema * sigema;
            //半径=3sigema
            int radius = Convert.ToInt16(Math.Ceiling(3 * sigema));
            int filterWidth = 2 * radius + 1;
            double[] filter = new double[filterWidth];
            outputImage = new double[inputImage.Length];

            //限定输入的情况为方阵的情况下得到的图像的宽度和高度
            int length = Convert.ToInt16(Math.Sqrt(inputImage.Length));
            double[] tempImage = new double[inputImage.Length];

            double sum = 0;
            //产生一维高斯函数
            for (int i = 0; i < filterWidth; i++)
            {
                int xx = (i - radius) * (i - radius);
                filter[i] = Math.Exp(-xx / std2);
                sum += filter[i];
            }

            //归一化
            for (int i = 0; i < filterWidth; i++)
            {
                filter[i] = filter[i] / sum;
            }

            //水平方向滤波
            for (int i = 0; i < length; i++)
            {
                for (int j = 0; j < length; j++)
                {
                    double temp = 0;
                    for (int k = -radius; k <= radius; k++)
                    {
                        //循环拓展
                        int rem = (Math.Abs(j + k) % length);
                        //计算卷积和
                        temp += inputImage[i * length + rem] * filter[k + radius];
                    }
                    tempImage[i + length + j] = temp;
                }
            }

            //垂直方向滤波
            for (int j = 0; j < length; j++)
            {
                for (int i = 0; i < length; i++)
                {
                    double temp = 0;
                    for (int k = -radius ; k <=radius; k++)
                    {
                        //循环拓展
                        int rem = (Math.Abs(i + k) )% length;

                        //计算卷积和
                        temp += tempImage[rem * length + j] * filter[k + radius];
                    }
                    outputImage[i * length + j] = temp;
                }
            }
        }

http://www.niftyadmin.cn/n/1783366.html

相关文章

判断是否联网

判断是否联网 在uses中加入WinInetif InternetCheckConnection(http://www.sina.com.cn,1,0) thenbegin showmessage(在线);endelsebegin showmessage(离线);end; 或直接用ping后&#xff0c;查看(0% loss)或(100% loss)&#xff0c;可知在线或离线

继承中的对象模型

1.父类中私有成员也是被子类继承下去了&#xff0c;只是由编译器给隐藏后访问不到 #include<iostream> using namespace std; #include<string>//继承方式 //父类中私有成员也是被子类继承下去了&#xff0c;只是由编译器给隐藏后访问不到 class Base { public:in…

apk反编译工具

1、最典型的apk编译工具的核心是apktool,但是因为操作需要调用cmd命令,所以出现了很多具有可视化界面的各种编译工具,像easyapk,apkdb,doapk 2、dex2jar.jar,将apk中的classes.dex转化成Jar文件&#xff0c;再通过jd-gui工具反编译jar文件。转载于:https://www.cnblogs.com/blu…

高斯低通滤波原理(图像处理)

一般来说&#xff0c;噪声都是由高频成分组成的&#xff0c;所以用低通滤波器对图像进行卷积处理&#xff0c;就可以有效地滤除噪声。 高斯函数就是一个这样的低通滤波器&#xff0c;它属于线性滤波。 高斯函数的主要特征&#xff1a;它的傅里叶变换函数仍然是高斯函数。 所…

JQuery调用WebService,以及JS把单斜杠转换成双斜杠

使用场景如下&#xff1a; 调用WebService文件上传。 首先是全路径问题&#xff0c;ie可以自动获取&#xff0c;但firefox不行&#xff0c;只能得到文件名&#xff0c;没有路径。 于是上网找解决办法&#xff1a; 解决代码如下&#xff1a; <!DOCTYPE html PUBLIC "-/…

继承中构造和析构顺序

1.子类继承父类后&#xff0c;当创建子类对象&#xff0c;也会调用父类的构造函数 2.继承中先调用父类构造函数&#xff0c;再调用子类构造函数&#xff0c;析构顺序与构造相反 #include<iostream> using namespace std; #include<string>//继承中的构造和析构顺…

C#边缘点跟踪方法(图像处理)

//边缘点跟踪方法//边缘跟踪&#xff0c;递归算法//k:图像纵坐标//l:图像横坐标//inputImage 梯度图像//outputImage 输出边缘图像//thrLow:低阈值private void traceEdge(int k,int l,double[]inputImage,ref byte[]outputImage,byte thrLow){//8领域int[] kOffset new int[]…

.NET Framework 4.0 XmlSerializer and automatic collection properties

System.Xml.Serialization.XmlSerializer反序列化类型包含集合自动属性运行在.NET Framework 4.0下则会抛出如下异常信息&#xff1a; System.InvalidOperationException: Unable to generate a temporary class (result1).error CS0200: Property or indexer SomeClass.Collec…