博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Win8 Metro(C#)数字图像处理--2.69中点滤波器
阅读量:7235 次
发布时间:2019-06-29

本文共 3636 字,大约阅读时间需要 12 分钟。

原文:

[函数代码]

        ///         /// Mid-point filter.        ///         /// The source image.        /// 
public static WriteableBitmap MidPointFilterProcess(WriteableBitmap src)中点滤波器 { if (src != null) { int w = src.PixelWidth; int h = src.PixelHeight; WriteableBitmap filterImage = new WriteableBitmap(w, h); byte[] temp = src.PixelBuffer.ToArray(); byte[] tempMask = (byte[])temp.Clone(); double[] Gray = new double[9]; double gray = 255, graymax = 0; int tempr = 0, tempb = 0, tempg = 0, temprMax = 0, tempgMax = 0, tempbMax = 0; for (int j = 1; j < h - 1; j++) { for (int i = 1; i < w - 1; i++) { tempb = 0; tempg = 0; tempr = 0; gray = 255; graymax = 0; int[] B = new int[9] { tempMask[i * 4 + j * w * 4], tempMask[(i - 1) * 4 + (j - 1) * w * 4], tempMask[i * 4 + (j - 1) * w * 4], tempMask[(i + 1) * 4 + (j - 1) * w * 4], tempMask[(i - 1) * 4 + j * w * 4], tempMask[(i + 1) * 4 + j * w * 4], tempMask[(i - 1) * 4 + (j + 1) * w * 4], tempMask[i * 4 + (j + 1) * w * 4], tempMask[(i + 1) * 4 + (j + 1) * w * 4] }; int[] G = new int[9] { tempMask[i * 4 + 1 + j * w * 4], tempMask[(i - 1) * 4 + 1 + (j - 1) * w * 4], tempMask[i * 4 + 1 + (j - 1) * w * 4], tempMask[(i + 1) * 4 + 1 + (j - 1) * w * 4], tempMask[(i - 1) * 4 + 1 + j * w * 4], tempMask[(i + 1) * 4 + 1 + j * w * 4], tempMask[(i - 1) * 4 + 1 + (j + 1) * w * 4], tempMask[i * 4 + 1 + (j + 1) * w * 4], tempMask[(i + 1) * 4 + 1 + (j + 1) * w * 4] }; int[] R = new int[9] { tempMask[i * 4 + 2 + j * w * 4], tempMask[(i - 1) * 4 + 2 + (j - 1) * w * 4], tempMask[i * 4 + 2 + (j - 1) * w * 4], tempMask[(i + 1) * 4 + 2 + (j - 1) * w * 4], tempMask[(i - 1) * 4 + 2 + j * w * 4], tempMask[(i + 1) * 4 + 2 + j * w * 4], tempMask[(i - 1) * 4 + 2 + (j + 1) * w * 4], tempMask[i * 4 + 2 + (j + 1) * w * 4], tempMask[(i + 1) * 4 + 2 + (j + 1) * w * 4] }; for (int n = 0; n < 9; n++) { Gray[n] = (double)B[n] * 0.114 + (double)G[n] * 0.587 + (double)R[n] * 0.299; if (gray > Gray[n]) { gray = Gray[n]; tempb = B[n]; tempr = R[n]; tempg = G[n]; } if (graymax < Gray[n]) { graymax = Gray[n]; tempbMax = B[n]; tempgMax = G[n]; temprMax = R[n]; } } temp[i * 4 + j * w * 4] = (byte)((tempb + tempbMax) / 2); temp[i * 4 + 1 + j * w * 4] = (byte)((tempg + tempgMax) / 2); temp[i * 4 + 2 + j * w * 4] = (byte)((tempr + temprMax) / 2); } } Stream sTemp = filterImage.PixelBuffer.AsStream(); sTemp.Seek(0, SeekOrigin.Begin); sTemp.Write(temp, 0, w * 4 * h); return filterImage; } else { return null; } }

[图像效果]

最后,分享一个专业的图像处理网站(微像素),里面有很多源代码下载:


你可能感兴趣的文章
devops之路第一篇(gitlab搭建)
查看>>
【跃迁之路】【436天】刻意练习系列195—Java基础练习(继承)(2018.04.17)
查看>>
NPM vs Yarn 备忘手册
查看>>
初识LVM及ECS上LVM分区扩容
查看>>
Vue作为组件在前端项目中的应用技巧
查看>>
python实现一个简单的并查集
查看>>
阻止微信浏览器下拉滑动效果(ios11.3 橡皮筋效果)
查看>>
支持所有JavaScript运行时的HTTP网络库-Fly.js
查看>>
【Sublime Text3 】——SublimeTmpl代码模板
查看>>
Java对象的使用
查看>>
【350天】我爱刷题系列109(2018.01.21)
查看>>
每个程序员都应该读《Unix编程艺术》
查看>>
彻底搞懂JavaScript中的继承
查看>>
python奇遇记:数据结构窥探3
查看>>
iOS-高性能
查看>>
无所遁形
查看>>
动态规划(2)——01背包
查看>>
使用递归遍历并转换树形数据(以 TypeScript 为例)
查看>>
css制作动画
查看>>
大型分布式网站的思考(一):大型网站发展历程
查看>>