原文: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. tcp注意点

    tcp注意点 tcp服务器一般情况下都需要绑定,否则客户端找不到这个服务器 tcp客户端一般不绑定,因为是主动链接服务器,所以只要确定好服务器的ip.port等信息就好,本地客户端可以随机 tcp服务 ...

  2. 概念的理解 —— 奇点(singularity point)、第一性原理(first principle)

    奇点(singularity point)一词出现在不同的环境里,对应着不同的含义: wikipedia:Singularity 文艺作品: 未来学(Futurology):比如雷·库兹韦尔的< ...

  3. 【matlab】GPU 显卡版本与计算能力(compute capability)兼容性问题

    MathWorks - Bug Reports 1. 问题说明 当运行 alexnet 等卷积神经网络需要使用 GPU 加速时,matlab 如果提示如下的警告信息: GPUs of compute ...

  4. erlang lists

    http://blog.csdn.net/dp0304/article/details/7590233 一,带函数Pred1, all(Pred, List) -> boolean()如果Lis ...

  5. 让Duilib多线程编程更easy

    一.Duilib不能开发多线程程序? 记得非常久曾经就听有人说过Duilib的多线程支持性不好,原因是Duilib里面的控件是用数组管理的全局变量,不能进行多线程訪问,加锁非常麻烦.事实上这个说法是非 ...

  6. Method and system for implementing mandatory file access control in native discretionary access control environments

    A method is provided for implementing a mandatory access control model in operating systems which na ...

  7. 利用WPF建立自己的3d gis软件(非axhost方式)(六)跳转,增加外部三维模型

    原文:利用WPF建立自己的3d gis软件(非axhost方式)(六)跳转,增加外部三维模型 先下载SDK:https://pan.baidu.com/s/1M9kBS6ouUwLfrt0zV0bPe ...

  8. 【Codeforces Round #438 A】Bark to Unlock

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] 枚举它是在连接处,还是就是整个字符串就好. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc+ ...

  9. H∞一般控制问题的鲁棒叙述性说明

    Robust Control System:反馈控制有承受一定类不确定能力的影响,这一直保持在这种不确定的条件(制)稳定.动态特性(灵敏度)和稳态特性(逐步调整)的能力. 非结构不确定性(Unstru ...

  10. js typeof instanceof

    一般都是用typeof推断变量存在 例如if(typeof a!="undefined"){}.不是要去使用if(a)因为假定a不存在(未申报)将是错误的. 由于typeof经验n ...