Win8 Metro(C#)数字图像处理--2.68图像最小值滤波器
2024-08-26 21:14:21
原文: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;
}
}
[图像效果]
最新文章
- ORACLE快速彻底Kill掉的会话
- javascript深入浅出(imooc)
- 【NHibernate】列“ReservedWord”不属于表 ReservedWords
- c# winForm使用Aspose.Cells读取CSV文件中文乱码问题
- 查看别人的css
- opencv+ffmpeg实现avi视频的播放
- Fast Matrix Operations
- linux image writes boot log to console
- Cocos2dx-3.1.1 冒险01----&;gt; 文件夹结构、新项目project创建并执行
- GLIBC_2.7升级
- 201521123103 《java学习笔记》 第十周学习总结
- String、StringBuffer、StringBuilder对比
- python 内置函数详解
- C++实验四
- 时间字符串格式化 js
- 理解position定位
- C# 16进制转 Brush 颜色对象
- Object类浅析
- 低危漏洞- X-Frame-Options Header未配置
- SharePoint 2013 地址栏_layouts/15/start.aspx#
热门文章
- [NPM] Use package.json variables in npm scripts
- BZOJ 1090 - 区间dp
- js取json对象的键和值
- fusionchart实现ZoomLine 资源 破解版 出口能力
- 过滤Filter推断用户是否登录
- linux下Java程序中插入DB中国的数据乱码问题
- Opencv均值漂移pyrMeanShiftFiltering彩色图像分割流程剖析
- centos安装启动ssh服务
- Network management system scheduling for low power and lossy networks
- jQuery插件开发小总结