原文:Win8 Metro(C#)数字图像处理--2.69中点滤波器

[函数代码]

<strong>        /// <summary>
/// Mid-point filter.
/// </summary>
/// <param name="src">The source image.</param>
/// <returns></returns>
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;
}
}</strong>

[图像效果]

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



最新文章

  1. 设计模式学习笔记-Adapter模式
  2. Kali连接数据库
  3. js闭包使用
  4. javascript判断变量是不是空值
  5. WinAPI: ShellExecute - 打开外部程序或文件
  6. 四、优化及调试--网站优化--Yahoo军规上
  7. oracle生成行方法
  8. Java DSL简介(收集整理)
  9. MVC Controller return 格式
  10. 浪漫桃心的Android表白程序
  11. C++ 性能剖析 (三):Heap Object对比 Stack (auto) Object
  12. Xcode 5.1.1 与 Xcode 6.0.1 共存
  13. IP包头
  14. Jquery源码分析与简单模拟实现
  15. centos7 部署dns服务器
  16. HNOI2018 滚粗记
  17. machine learning 之 Neural Network 3
  18. 【差分+前缀和】BZOJ1637: [Usaco2007 Mar]Balanced Lineup
  19. call、apply、bind的用法
  20. Android几种强大的下拉刷新库

热门文章

  1. Android的NDK开发(1)————Android JNI简介与调用流程
  2. 辛星浅析yaf框架中的类的自己主动载入问题
  3. android通用適配器
  4. js中 慎用for(var o in arrays) 遍历数组,for(var i,i&lt; objects.length;i++)与for(var i,n = objects.length;i&lt;n;i++) 的性能区别
  5. Delphi 7验证XML合法性(利用DTD、XSD)
  6. 在jsp页面里面设置全局引用文件
  7. AnimatorSet和PropertyValuesHolders.ofKeyframe
  8. 【38.46%】【codeforces 615E】Hexagons
  9. 分布式系统和CAP
  10. Spring 的 ApplicationEvent and ApplicationListener