原文:Win8 Metro(C#)数字图像处理--2.51图像统计滤波算法



[函数名称]

  图像统计滤波   WriteableBitmap StatisticalFilter(WriteableBitmap src,double T)

/// <summary>
/// Statistical filtering process.
/// </summary>
/// <param name="src">The source image.</param>
/// <param name="T">The threshould to adjust filter effect.</param>
/// <returns></returns>
public static WriteableBitmap StatisticalFilter(WriteableBitmap src,double T)////图像统计滤波
{
if (src != null)
{
int w = src.PixelWidth;
int h = src.PixelHeight;
WriteableBitmap srcImage = new WriteableBitmap(w, h);
byte[] temp = src.PixelBuffer.ToArray();
byte[] tempMask = (byte[])temp.Clone();
double mean = 0;
double std = 0;
int[] windowValue = new int[9];
double mR = 0;
double mG = 0;
double mB = 0;
for (int j = 1; j < h-1; j++)
{
for (int i = 1; i < w-1; i++)
{
windowValue[0] = (int)(tempMask[(i - 1) * 4 + (j - 1) * w * 4] * 0.114 + tempMask[(i - 1) * 4 + 1 + (j - 1) * w * 4] * 0.587 + tempMask[(i - 1) * 4 + 2 + (j - 1) * w * 4] * 0.299);
windowValue[1] = (int)(tempMask[i * 4 + (j - 1) * w * 4] * 0.114 + tempMask[i * 4 + 1 + (j - 1) * w * 4] * 0.587 + tempMask[i * 4 + 2 + (j - 1) * w * 4] * 0.299);
windowValue[2] = (int)(tempMask[(i + 1) * 4 + (j - 1) * w * 4] * 0.114 + tempMask[(i + 1) * 4 + 1 + (j - 1) * w * 4] * 0.587 + tempMask[(i + 1) * 4 + 2 + (j - 1) * w * 4] * 0.299);
windowValue[3] = (int)(tempMask[(i-1) * 4 + j * w * 4] * 0.114 + tempMask[(i-1) * 4 + 1 + j * w * 4] * 0.587 + tempMask[(i - 1) * 4 + 2 + j * w * 4] * 0.299);
windowValue[4] = (int)(tempMask[i * 4 + j * w * 4] * 0.114 + tempMask[i * 4 + 1 + j * w * 4] * 0.587 + tempMask[i * 4 + 2 + j * w * 4] * 0.299);
windowValue[5] = (int)(tempMask[(i + 1) * 4 + j * w * 4] * 0.114 + tempMask[(i + 1) * 4 + 1 + j * w * 4] * 0.587 + tempMask[(i + 1) * 4 + 2 + j * w * 4] * 0.299);
windowValue[6] = (int)(tempMask[(i - 1) * 4 + (j + 1) * w * 4] * 0.114 + tempMask[(i - 1) * 4 + 1 + (j + 1) * w * 4] * 0.587 + tempMask[(i - 1) * 4 + 2 + (j + 1) * w * 4] * 0.299);
windowValue[7] = (int)(tempMask[i * 4 + (j + 1) * w * 4] * 0.114 + tempMask[i * 4 + 1 + (j + 1) * w * 4] * 0.587 + tempMask[i * 4 + 2 + (j + 1) * w * 4] * 0.299);
windowValue[8] = (int)(tempMask[(i + 1) * 4 + (j + 1) * w * 4] * 0.114 + tempMask[(i + 1) * 4 + 1 + (j + 1) * w * 4] * 0.587 + tempMask[(i + 1) * 4 + 2 + (j + 1) * w * 4] * 0.299);
for (int n = 0; n < 9; n++)
{
mean += (double)((double)(windowValue[n]) / 9);
}
for (int n = 0; n < 9; n++)
{
std += Math.Pow((double)(windowValue[n]) - mean, 2)/9;
}
if (windowValue[4] >= T * Math.Sqrt(std))
{
for (int k = -1; k < 2; k++)
{
for (int m = -1; m < 2; m++)
{
mB += (double)tempMask[(i + m) * 4 + (j + k) * w * 4] / 9;
mG += (double)tempMask[(i + m) * 4 + 1 + (j + k) * w * 4] / 9;
mR += (double)tempMask[(i + m) * 4 + 2 + (j + k) * w * 4] / 9;
}
}
temp[i * 4 + j * w * 4] = (byte)mB;
temp[i * 4 + 1 + j * w * 4] = (byte)mG;
temp[i * 4 + 2 + j * w * 4] = (byte)mR;
}
mean = 0;
std = 0;
mR = mG = mB = 0;
}
}
Stream sTemp = srcImage.PixelBuffer.AsStream();
sTemp.Seek(0, SeekOrigin.Begin);
sTemp.Write(temp, 0, w * 4 * h);
return srcImage;
}
else
{
return null;
}
}


Win8 Metro(C#)数字图像处理--2.51图像统计滤波算法的更多相关文章

  1. Win8 Metro(C#)数字图像处理--2.64图像高斯滤波算法

    原文:Win8 Metro(C#)数字图像处理--2.64图像高斯滤波算法  [函数名称]   高斯平滑滤波器      GaussFilter(WriteableBitmap src,int r ...

  2. Win8 Metro(C#)数字图像处理--2.44图像油画效果算法

    原文:Win8 Metro(C#)数字图像处理--2.44图像油画效果算法  [函数名称]   图像油画效果      OilpaintingProcess(WriteableBitmap src ...

  3. Win8 Metro(C#)数字图像处理--2.43图像马赛克效果算法

    原文:Win8 Metro(C#)数字图像处理--2.43图像马赛克效果算法  [函数名称] 图像马赛克效果        MosaicProcess(WriteableBitmap src, i ...

  4. Win8 Metro(C#)数字图像处理--2.35图像肤色检测算法

    原文:Win8 Metro(C#)数字图像处理--2.35图像肤色检测算法  [函数名称] 肤色检测函数SkinDetectProcess(WriteableBitmap src) [算法说明] ...

  5. Win8 Metro(C#)数字图像处理--3.2图像方差计算

    原文:Win8 Metro(C#)数字图像处理--3.2图像方差计算 /// <summary> /// /// </summary>Variance computing. / ...

  6. Win8 Metro(C#)数字图像处理--3.3图像直方图计算

    原文:Win8 Metro(C#)数字图像处理--3.3图像直方图计算 /// <summary> /// Get the array of histrgram. /// </sum ...

  7. Win8 Metro(C#)数字图像处理--3.4图像信息熵计算

    原文:Win8 Metro(C#)数字图像处理--3.4图像信息熵计算 [函数代码] /// <summary> /// Entropy of one image. /// </su ...

  8. Win8 Metro(C#)数字图像处理--3.5图像形心计算

    原文:Win8 Metro(C#)数字图像处理--3.5图像形心计算 /// <summary> /// Get the center of the object in an image. ...

  9. Win8 Metro(C#)数字图像处理--3.1图像均值计算

    原文:Win8 Metro(C#)数字图像处理--3.1图像均值计算 /// <summary> /// Mean value computing. /// </summary> ...

随机推荐

  1. 批量解决 word/wps 中公式和文字不对齐的问题

    完美解决Word或wps中中公式和文字对不齐的问题 在 word 的各个版本中,当公式和字符同时出现时,尤其是发生公式的拷贝粘贴时,公式往往会出现上飘或下移的情况,这里给出一个简单易行的解决方案: 全 ...

  2. dom对象常用的属性和方法有哪些?

    dom对象常用的属性和方法有哪些? 一.总结 一句话总结: 1.document属性和方法:document的属性有head,body之类,方法有各种获取element的方法 2.element的属性 ...

  3. Android ReentrantLock

    synchronized原语和ReentrantLock在一般情况下没有什么区别,但是在非常复杂的同步应用中,请考虑使用ReentrantLock,特别是遇到下面2种需求的时候. 1.某个线程在等待一 ...

  4. 安装 Visual Studio,连接中国区 Azure

    中国数据中心 目前,中国区 Azure 有两个数据中心,在位置字段中显示为“中国北部”和“中国东部”. 在 Azure 上创建应用程序的区别 在中国区 Azure 上开发应用程序与在境外 Azure ...

  5. js获取计算后的样式表

    在编写html时,使用dom对象的style属性可以获取标签里的style属性,但是不能获取单独css样式文件或者style标签的属性值 <div style="width:10px& ...

  6. 选择性编译代码:如 #ifdef __IPHONE_7_0

    选择性编译代码: 选择性编译代码和选择性运行代码是不一样的,区别在于: 1.选择性编译代码是在硬件或者系统不支持的情况下不会对该段代码进行编译,也就不会由于不兼容的问题导致报错 #import < ...

  7. Web静态服务器

    Web静态服务器 编程微刊 Web静态服务器-1-显示固定的页面 #coding=utf-8 import socket def handle_client(client_socket): " ...

  8. Git命令小总结

    常用 git init git 初始化 git clone https://github.com/wsxx111/thisStudy.git 从远端拉下来 git status 查看跟踪状态 git ...

  9. 设计模式在JDK中的应用

    在JDK(Java Development Kit)类库中,开发人员使用了大量设计模式. 创建型模式: (1) 抽象工厂模式(Abstract Factory) • java.util.Calenda ...

  10. 开发Android项目中使用androidannotations

    前言 最近接手了一个工程,使用了androidannotations,因为以前使用过butterknife所以有似曾相识的感觉,但是有些用法还是不一样,所以就花时间学习了下androidannotat ...