Step1:首先参考我之前的文章,将图像与二维数组互转
Step2:中值滤波C#函数
“中值滤波” 公式 private void button1_Cli孔雀鱼烂尾ck(object sender, EventArgs e) { byte[,] data;//[mH,mW] Bitmap bmp = new Bitmap(@"F:\MyDo\C#\测试用\IMGA\盐椒噪音.jpg"); pictureBox1.BackgroundImage = bmp; data = Image_2_Arry2D(bmp);//参照 Step1 data = sf_medianFilter(data); Bitmap img = Arry2D_2_Image(data);//参照 Step1 pictureBox2.BackgroundImage = img; } public static byte[,] sf_medianFilter(byte[,] sMat) { int mH = sMat.GetLength(0); int mW = sMat.GetLength(1); byte[,] Mat = new byte[mH, mW]; byte[] block = new byte[9]; for(int y=1;y<mH-1;y++) { for(int x=1;x<mW-1;x++) { block[0] = sMat[y-1, x+1]; block[1] = sMat[bl校园文y-1, x]; block[2] = sMat[y-1, x-1]; block[3] = sMat[y, x+1]; block[4] = sMat[y, x]; 鱼鳞病图片 block[5] = sMat[y, x-1]; block[6] = sMat[y+1, x+1]; block[7] = sMat[y+1, x]; block[8] = sMat[y+1, x-1]; sf_BubbleSort(ref block)怎么注册公司; Mat[y, x] = block[4]; } } return Mat; } publi三维试衣c static void sf_BubbleSort(ref byte[] Mat) { int len = Mat.GetLength(0); byte temp = 0; for(int i=0;i<len-1;i++) { for(int j=i+1;j<len;j++) { if(Mat[i]>Mat[j]) { temp = Mat[i]; Mat[i] = Mat[j]; Mat[j] = temp; } } } }Step3:运行效果
中值滤波(忽略边缘像素)扩展:与中值滤波算法很类似的有:
最大值滤波,最小值滤波,均值滤波。
最大值滤波器,发现图像中最亮点非常有用;对于椒噪声具有良好效果。最小值滤女人不坏男人不爱波器,发现图像中最暗点非常有用;对于盐噪声具有良好效果。均值滤波主要还是平滑图像的用处,有的图像的锐度很高,用这样的均值算法,可以把锐度降低。使得图像看上去更加自然。最大值滤波C#函数
“最大值滤波”公式public static byte[,] sf_minvalFilter(byte[,] sMat) { int mH = sMat.GetLength(0); int mW = sMat.GetLength(1); byte[,] Mat = new byte[mH, mW]; 境外投资byte temp = 0; for (int y = 1; y < mH - 1; y++) { for (int x = 1; x < mW - 1; x++) { temp = sMat[y, x]; temp = temp < sMat[y + 1, x]电视投影仪 ? temp : sMat[y + 1, x]; temp = temp < sMat[y - 1, x] ? temp : sMat[y - 1, x]; temp = temp < sMat[y, x - 1] ? temp : sMat[y, x - 1]; temp = temp < sMat[y + 1, x - 1] ? temp : sMat[y + 1, x - 1]; temp = temp &l旅游北京t; sMat[y - 1, x - 1] ? temp : sMat[y - 1, x - 1]; temp = temp < sMat[y, x + 1] ? temp : sMat[y, x + 1]; temp = temp < sMat[y + 1, x + 1] ? temp : sMat[y + 1, x + 1]; temp = temp < sMat[y - 1, x + 1] ? temp : sMat[y - 1, x + 1]; Mat[y,3000左右的手机 x] = temp; } } 新年用英语怎么说 return Mat; }效果:
“最大值滤波 ”白底 椒噪去除最小值滤波C#函数
“最小值滤波”公式public static byte[,] sf_minvalFilter(byte[,] sMat) { int mH = sMat.GetLength(0); int mW = sMat.GetLength(1); byte[,] Mat = new byte[mH, mW]; 张敬轩图片 byte temp = 0; for (int y = 1; y < mH - 1; y++) { for (int x = 1; x < mW - 1; x++) { temp = sMat[y, x]; temp = temp < sM雷思海at[y + 1, x] ? temp : sMat[y + 1, x]; temp = temp < sMat[y - 1, x] ? temp : sMat[y - 1, x]; temp = temp < sMat[y, x - 1] ? temp : sMat[y人体自然, x - 1]; temp = temp < sMat[y + 1, x - 1] ? temp : sMat[y + 1, x - 1]; temp = temp < sMat[y - 1, x - 1] ? temp :球磨 sMat[y - 1, x - 1]; temp = temp < sMat[y, x + 1] ? temp : sMat[y, x + 1]; temp = temp < sMat[y + 1, x + 1] ? temp : sMat[y + 1, x + 1]; temp = temp < sMat[y - 1, x + 1] ? temp : 凯恩斯sMat[y - 1, x + 1]; Mat[y, x] = temp; } } return Mat; }效果:
“最小值滤波” 文字 盐噪去除均值滤波C#函数
均值滤波 公式public static byte[,] sf_meanFilter(by阿玛尼满天星te[,] sMat) { int mH = sMat.GetLength(0); int mW = sMat.GetLength(1); byte[,] Mat = new byte[mH, mW]; int temp = 0; for (int y = 1; y < mH - 1; y++) { for (int x = 1; x < mW - 1; x++) { temp = sMat[y - 1, x + 1]; temp += sMat[y - 1, x]; temp += sMat[y - 1, x - 1]; temp += sMat[y, x + 1]; temp += sMat[y, x]; temp += sMat[y, x - 1]; temp += sMat[y + 1, x + 1]; 校园安全知识 temp += sMat[y + 1, x]; temp += sMat[y + 1, x - 1]; Mat[y, x] = (byte)(temp/9); } } 油墨印刷 return Mat; }效果:
“均值滤波” 盐椒噪 均淡化“均值滤波” 效果本文发布于:2023-06-01 23:41:24,感谢您对本站的认可!
本文链接:http://www.ranqi119.com/ge/85/182850.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |