原文:Win8 Metro(C#)数字图像处理--2.68图像最小值滤波器

        /// <summary>
/// Min value filter.
/// </summary>
/// <param name="src">The source image.</param>
/// <returns></returns>
public static WriteableBitmap MinFilterProcess(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;
int tempr = 0, tempb = 0, tempg = 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;
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];
}
}
temp[i * 4 + j * w * 4] = (byte)tempb;
temp[i * 4 + 1 + j * w * 4] = (byte)tempg;
temp[i * 4 + 2 + j * w * 4] = (byte)tempr;
}
}
Stream sTemp = filterImage.PixelBuffer.AsStream();
sTemp.Seek(0, SeekOrigin.Begin);
sTemp.Write(temp, 0, w * 4 * h);
return filterImage;
}
else
{
return null;
}
}

[图像效果]



最新文章

  1. ORACLE快速彻底Kill掉的会话
  2. javascript深入浅出(imooc)
  3. 【NHibernate】列“ReservedWord”不属于表 ReservedWords
  4. c# winForm使用Aspose.Cells读取CSV文件中文乱码问题
  5. 查看别人的css
  6. opencv+ffmpeg实现avi视频的播放
  7. Fast Matrix Operations
  8. linux image writes boot log to console
  9. Cocos2dx-3.1.1 冒险01----&amp;gt; 文件夹结构、新项目project创建并执行
  10. GLIBC_2.7升级
  11. 201521123103 《java学习笔记》 第十周学习总结
  12. String、StringBuffer、StringBuilder对比
  13. python 内置函数详解
  14. C++实验四
  15. 时间字符串格式化 js
  16. 理解position定位
  17. C# 16进制转 Brush 颜色对象
  18. Object类浅析
  19. 低危漏洞- X-Frame-Options Header未配置
  20. SharePoint 2013 地址栏_layouts/15/start.aspx#

热门文章

  1. [NPM] Use package.json variables in npm scripts
  2. BZOJ 1090 - 区间dp
  3. js取json对象的键和值
  4. fusionchart实现ZoomLine 资源 破解版 出口能力
  5. 过滤Filter推断用户是否登录
  6. linux下Java程序中插入DB中国的数据乱码问题
  7. Opencv均值漂移pyrMeanShiftFiltering彩色图像分割流程剖析
  8. centos安装启动ssh服务
  9. Network management system scheduling for low power and lossy networks
  10. jQuery插件开发小总结