原文: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. [Angular] NgRx/effect, why to use it?

    See the current implementaion of code, we have a smart component, and inside the smart component we ...

  2. 数组filter方法对数组元素进行过滤

    Array.prototype.filter对数组中元素进行过滤 /** * @method reduce * @param {number} item 当前迭代的数组元素 * @param {num ...

  3. oracle11g 在azure云中使用rman进行实例迁移

    1,開始备份 备份脚本rman_full_backup.sh内容例如以下: #!/bin/sh export DATE=`date +%F` export BACK_DIR='/backupdisk/ ...

  4. Quartz2D常见图形的绘制:线条、多边形、圆

    UI高级 Quartz2D http://ios.itcast.cn  iOS学院 掌握 drawRect:方法的使用 常见图形的绘制:线条.多边形.圆 绘图状态的设置:文字颜色.线宽等 图形上下文状 ...

  5. 理解Erlang/OTP - Application

    http://www.cnblogs.com/me-sa/archive/2011/12/27/erlang0025.html 1>application:start(log4erl). 我们就 ...

  6. 小强的HTML5移动开发之路(33)—— jqMobi基础

    一.什么是jqMobi jqMobi是由appMobi针对HTML5浏览器和移动设备开发的javascript框架,是个极快速的查询选择库,支持W3C查询. 版本 jqMobi源码最初在2012年1月 ...

  7. svn服务配置

    1关闭所有svn服务 nie-xiao-bo-mac-pro:svnproject mac$ killall -9 svnserve 2.开启某文件路径svn服务 nie-xiao-bo-mac-pr ...

  8. 一起学Python:正则表达式概述

    re模块操作 在Python中需要通过正则表达式对字符串进行匹配的时候,可以使用一个模块,名字为re 1. re模块的使用过程 #coding=utf-8 # 导入re模块 import re # 使 ...

  9. 【22.73%】【codeforces 606D】Lazy Student

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  10. android之照相、相冊裁剪功能的实现过程

    今天无聊做了一些照相.相冊裁剪功能,希望能够帮到大家! 不多说了,贴代码实际一点: 首先是XML: <ImageButton android:id="@+id/imageButton1 ...