原文:Win8Metro(C#)数字图像处理--2.10图像中值滤波



[函数名称]

图像中值滤波函数MedianFilterProcess(WriteableBitmap
src)

[函数代码]

///<summary>

///
Median filter process.

///</summary>

///<param
name="src">Source image.</param>

///<returns></returns>

publicstaticWriteableBitmap
MedianFilterProcess(WriteableBitmap src)////10中值滤波处理

{

if(src!=null
)

{

int
w = src.PixelWidth;

int
h = src.PixelHeight;

WriteableBitmap
filterImage =newWriteableBitmap(w,
h);

byte[]
temp = src.PixelBuffer.ToArray();

byte[]
tempMask = (byte[])temp.Clone();

int
v1 = 0, v2 = 0, v3 = 0, v4 = 0, v5 = 0, v6 = 0, v7 = 0, v8 = 0, t = 0;

for
(int j = 1; j < h - 1; j++)

{

for
(int i = 4; i < w * 4 - 4; i += 4)

{

v1 = (int)(temp[i
- 4 + (j - 1) * w * 4] * 0.114 + temp[i - 4 + 1 + (j - 1) * w * 4] * 0.587 + temp[i - 4 + 2 + (j - 1) * w * 4] * 0.299);

v2 = (int)(temp[i
+ (j - 1) * w * 4] * 0.114 + temp[i + 1 + (j - 1) * w * 4] * 0.587 + temp[i + 2 + (j - 1) * w * 4] * 0.299);

v3 = (int)(temp[i
+ 4 + (j - 1) * w * 4] * 0.114 + temp[i + 4 + 1 + (j - 1) * w * 4] * 0.587 + temp[i + 4 + 2 + (j - 1) * w * 4] * 0.299);

v4 = (int)(temp[i
- 4 + j * w * 4] * 0.114 + temp[i - 4 + 1 + j * w * 4] * 0.587 + temp[i - 4 + 2 + j * w * 4] * 0.299);

v5 = (int)(temp[i
+ 4 + j * w * 4] * 0.114 + temp[i + 4 + 1 + j * w * 4] * 0.587 + temp[i + 4 + 2 + j * w * 4] * 0.299);

v6 = (int)(temp[i
- 4 + (j + 1) * w * 4] * 0.114 + temp[i - 4 + 1 + (j + 1) *w * 4] * 0.587 + temp[i - 4 + 2 + (j + 1) * w * 4] * 0.299);

v7 = (int)(temp[i
+ (j + 1) * w * 4] * 0.114 + temp[i + 1 + (j + 1) * w * 4] * 0.587 + temp[i + 2 + (j + 1) * w * 4] * 0.299);

v8 = (int)(temp[i
+ 4 + (j + 1) * w * 4] * 0.114 + temp[i + 4 + 1 + (j + 1) * w * 4] * 0.587 + temp[i + 4 + 2 + (j + 1) * w * 4] * 0.299);

t = GetMedianValue(v1, v2, v3, v4, v5, v6, v7, v8);

if(t==v1)

{

temp[i + j * w * 4] = (byte)tempMask[i
- 4 + (j - 1) * w * 4];

temp[i + 1 + j * w * 4] = (byte)tempMask[i
- 4 + 1 + (j - 1) * w * 4];

temp[i + 2 + j * w* 4] = (byte)tempMask[i
- 4 + 2 + (j - 1) * w * 4];

}

elseif(t==v2)

{

temp[i + j * w * 4] = (byte)tempMask[i
+ (j - 1) * w * 4];

temp[i + 1 + j * w * 4] = (byte)tempMask[i
+ 1 + (j - 1) * w * 4];

temp[i + 2 + j * w * 4] = (byte)tempMask[i
+ 2 + (j - 1) * w * 4];

}

elseif(t==v3)

{

temp[i + j * w * 4] = (byte)tempMask[i
+ 4 + (j - 1) * w * 4];

temp[i + 1 + j * w * 4] = (byte)tempMask[i
+ 1 + 4 + (j - 1) * w * 4];

temp[i + 2 + j * w * 4] = (byte)tempMask[i
+ 2 + 4 + (j - 1) * w * 4];

}

elseif(t==v4)

{

temp[i + j * w * 4] = (byte)tempMask[i
- 4 + j * w * 4];

temp[i + 1 + j * w * 4] = (byte)tempMask[i
- 4 + 1 + j * w * 4];

temp[i + 2 + j * w * 4] = (byte)tempMask[i
- 4 + 2 + j * w * 4];

}

elseif(t==v5)

{

temp[i + j * w * 4] = (byte)tempMask[i
+ 4 + j * w * 4];

temp[i + 1 + j * w * 4] = (byte)tempMask[i
+ 4 + 1 + j * w * 4];

temp[i + 2 + j * w * 4] = (byte)tempMask[i
+ 4 + 2 + j * w * 4];

}

elseif(t==v6)

{

temp[i + j * w * 4] = (byte)tempMask[i
- 4 + (j + 1) * w * 4];

temp[i + 1 + j * w * 4] = (byte)tempMask[i
- 4 + 1 + (j + 1) * w * 4];

temp[i + 2 + j * w * 4] = (byte)tempMask[i
- 4 + 2 + (j + 1) * w * 4];

}

elseif
(t == v7)

{

temp[i + j * w * 4] = (byte)tempMask[i
+ (j + 1) * w * 4];

temp[i + 1 + j * w * 4] = (byte)tempMask[i
+ 1 + (j + 1) * w * 4];

temp[i + 2 + j * w * 4] = (byte)tempMask[i
+ 2 + (j + 1) * w * 4];

}

else

{

temp[i + j * w * 4] = (byte)tempMask[i
+ 4 + (j + 1) * w * 4];

temp[i + 1 + j * w * 4] = (byte)tempMask[i
+ 4 + 1 + (j + 1) * w * 4];

temp[i + 2 + j * w * 4] = (byte)tempMask[i
+ 4 + 2 + (j + 1) * w * 4];

}

v1 = 0; v2 = 0; v3 = 0; v4 = 0; v5 = 0; v6 = 0; v7 = 0; v8 = 0; t = 0;

}

}

Stream
sTemp = filterImage.PixelBuffer.AsStream();

sTemp.Seek(0,SeekOrigin.Begin);

sTemp.Write(temp, 0, w * 4 * h);

return
filterImage;

}

else

{

returnnull;

}

}

privatestaticint
GetMedianValue(paramsint[]
src)

{

int
w = src.Length;

int
temp = src[0], m = 0;

for
(int i = 1; i < (int)(w
/ 2); i++)

{

if
(src[i] < temp)

{

m = src[i];

src[i] = temp;

temp = m;

}

else

continue;

}

return
(int)((src[(int)(w
/ 2)] + src[(int)(-1 + w / 2)]) / 2);

}


Win8Metro(C#)数字图像处理--2.10图像中值滤波的更多相关文章

  1. Win8Metro(C#)数字图像处理--2.3图像反色

    原文:Win8Metro(C#)数字图像处理--2.3图像反色 [函数名称] 图像反色函数ContraryProcess(WriteableBitmap src) [算法说明]     反色公式如下: ...

  2. Win8MetroC#数字图像处理--2.2图像二值化函数

    原文:Win8MetroC#数字图像处理--2.2图像二值化函数 [函数代码] /// <summary> /// Binary process. /// </summary> ...

  3. Win8Metro(C#)数字图像处理--2.4图像颜色聚类

    原文:Win8Metro(C#)数字图像处理--2.4图像颜色聚类  [函数名称] 图像颜色聚类函数ClusterProcess(WriteableBitmap src,int value) [算 ...

  4. Win8Metro(C#)数字图像处理--2.33图像非线性变换

    原文:Win8Metro(C#)数字图像处理--2.33图像非线性变换  [函数名称] 图像非线性变换函数NonlinearTransformProcess(WriteableBitmap src ...

  5. Win8Metro(C#)数字图像处理--2.32图像曝光算法

    原文:Win8Metro(C#)数字图像处理--2.32图像曝光算法  [函数名称] 图像曝光函数ExposureProcess(WriteableBitmap src,int exposureV ...

  6. Win8Metro(C#)数字图像处理--2.27图像加法运算

    原文:Win8Metro(C#)数字图像处理--2.27图像加法运算  [函数名称] 图像加法函数AddProcess(WriteableBitmap src, WriteableBitmap a ...

  7. Win8Metro(C#)数字图像处理--2.28图像乘法运算

    原文:Win8Metro(C#)数字图像处理--2.28图像乘法运算  [函数名称] 图像乘法函数MultiplicationProcess(WriteableBitmap src, Writea ...

  8. Win8Metro(C#)数字图像处理--2.29图像除法运算

    原文:Win8Metro(C#)数字图像处理--2.29图像除法运算  [函数名称] 图像除法函数DivisionProcess(WriteableBitmap src, WriteableBit ...

  9. Win8Metro(C#)数字图像处理--2.26图像减法

    原文:Win8Metro(C#)数字图像处理--2.26图像减法  [函数名称] 图像减法函数SubtractionProcess(WriteableBitmap src, WriteableBi ...

随机推荐

  1. C#-numericUpDown-数字选择---ShinePans

    program.cs using System; using System.Collections.Generic; using System.Linq; using System.Windows.F ...

  2. matplotlib 可视化 —— cmap(colormap)

    color example code: colormaps_reference.py - Matplotlib 2.0.0 documentation 由其文档可知,在 colormap 类别上,有如 ...

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

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

  4. Role-based access control modeling and auditing system

    A role-based access control (RBAC) modeling and auditing system is described that enables a user to  ...

  5. 小强的HTML5移动开发之路(21)—— PhoneGap

    一.PhoneGap是什么 PhoneGap 是一个用基于 HTML,CSS 和 JavaScript 的,创建移动跨平台移动应用程序的快速开发框架.它使开发者能够利用 iPhone,Android, ...

  6. 【33.33%】【codeforces 586D】Phillip and Trains

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. TCP基础

    TCP基础知识 复习   前言 说来惭愧,大二时候学的计算机网络好多都不太记得了,不过还好有认真学过,捡起来也挺快的,就是对于现在业界中使用的网络算法的不是很懂: 1 TCP报文段结构 1.1 序号和 ...

  8. vultr的80端口?

    1.查看防火墙版本号firewall-cmd --version2.查看防火墙状态firewall-cmd --state3.添加80端口的权限firewall-cmd --zone=public - ...

  9. JS高级程序设计拾遗

    <JavaScript高级程序设计(第三版)>反反复复看了好多遍了,这次复习作为2017年上半年的最后一次,将所有模糊的.记不清的地方记录下来,方便以后巩固. 0. <script& ...

  10. CUDA atomic原子操作

    CUDA的原子操作可以理解为对一个变量进行"读取-修改-写入"这三个操作的一个最小单位的执行过程,这个执行过程不能够再分解为更小的部分,在它执行过程中,不允许其他并行线程对该变量进 ...