原文:Win8 Metro(C#)数字图像处理--2.50图像运动模糊



[函数名称]

图像运动模糊算法    MotionblurProcess(WriteableBitmap src,int k,int direction)

[算法说明]

运动模糊是指在摄像机获取图像时,由于景物和相机之间的相对运动而造成的图像上的模糊。这里

我们主要介绍匀速直线运动所造成的模糊,由于非匀速直线运动在某些条件下可以近似为匀速直线

运动,或者可以分解为多个匀速直线运动的合成,因此,在摄像机较短的图像曝光时间内,造成图

像模糊的运动情况可以近似为匀速直线运动。

对于匀速直线运动,图像的运动模糊可以用以下公式表示:

       /// <summary>
/// Motion blur process.
/// </summary>
/// <param name="src">The source image.</param>
/// <param name="k">The offset of motion, from 0 to 200.</param>
/// <param name="direction">The direction of motion, x:1, y:2.</param>
/// <returns></returns>
public static WriteableBitmap MotionblurProcess(WriteableBitmap src,int k,int direction)////运动模糊处理
{
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();
int b, g, r;
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x ++)
{
b = g = r = 0;
switch (direction)
{
case 1:
if (x >= k)
{
for (int i = 0; i <= k; i++)
{
b += (int)tempMask[(x - i) * 4 + y * w * 4];
g += (int)tempMask[(x - i) * 4 + 1 + y * w * 4];
r += (int)tempMask[(x - i) * 4 + 2 + y * w * 4];
}
temp[x * 4 + y * w * 4] = (byte)(b / (k + 1));
temp[x * 4 + 1 + y * w * 4] = (byte)(g / (k + 1));
temp[x * 4 + 2 + y * w * 4] = (byte)(r / (k + 1));
}
else
{
if (x > 0)
{
for (int i = 0; i < x; i++)
{
b += (int)tempMask[(x - i) * 4 + y * w * 4];
g += (int)tempMask[(x - i) * 4 + 1 + y * w * 4];
r += (int)tempMask[(x - i) * 4 + 2 + y * w * 4];
}
temp[x * 4 + y * w * 4] = (byte)(b/(x+1));
temp[x * 4 + 1 + y * w * 4] = (byte)(g/(x+1));
temp[x * 4 + 2 + y * w * 4] = (byte)(r/(x+1));
}
else
{
temp[x * 4 + y * w * 4] = (byte)(tempMask[x * 4 + y * w * 4] / k);
temp[x * 4 + 1 + y * w * 4] = (byte)(tempMask[x * 4 + 1 + y * w * 4] / k);
temp[x * 4 + 2 + y * w * 4] = (byte)(tempMask[x * 4 + 2 + y * w * 4] / k);
}
}
break;
case 2:
if (y >= k)
{
for (int i = 0; i <= k; i++)
{
b += (int)tempMask[x * 4 + (y - i) * w * 4];
g += (int)tempMask[x * 4 + 1 + (y - i) * w * 4];
r += (int)tempMask[x * 4 + 2 + (y - i) * w * 4];
}
temp[x * 4 + y * w * 4] = (byte)(b / (k + 1));
temp[x * 4 + 1 + y * w * 4] = (byte)(g / (k + 1));
temp[x * 4 + 2 + y * w * 4] = (byte)(r / (k + 1));
}
else
{
if (y > 0)
{
for (int i = 0; i < y; i++)
{
b += (int)tempMask[x * 4 + (y - i) * w * 4];
g += (int)tempMask[x * 4 + 1 + (y - i) * w * 4];
r += (int)tempMask[x * 4 + 2 + (y - i) * w * 4];
}
temp[x * 4 + y * w * 4] = (byte)(b/(y+1));
temp[x * 4 + 1 + y * w * 4] = (byte)(g/(y+1));
temp[x * 4 + 2 + y * w * 4] = (byte)(r/(y+1));
}
else
{
temp[x * 4 + y * w * 4] = (byte)(tempMask[x * 4 + y * w * 4] / k);
temp[x * 4 + 1 + y * w * 4] = (byte)(tempMask[x * 4 + 1 + y * w * 4] / k);
temp[x * 4 + 2 + y * w * 4] = (byte)(tempMask[x * 4 + 2 + y * w * 4] / k);
}
}
break;
default :
break;
}
}
}
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.50图像运动模糊的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. Win8 Metro(C#)数字图像处理--2.74图像凸包计算

    原文:Win8 Metro(C#)数字图像处理--2.74图像凸包计算 /// <summary> /// Convex Hull compute. /// </summary> ...

  7. Win8 Metro(C#)数字图像处理--2.68图像最小值滤波器

    原文:Win8 Metro(C#)数字图像处理--2.68图像最小值滤波器 /// <summary> /// Min value filter. /// </summary> ...

  8. Win8 Metro(C#)数字图像处理--2.52图像K均值聚类

    原文:Win8 Metro(C#)数字图像处理--2.52图像K均值聚类  [函数名称]   图像KMeans聚类      KMeansCluster(WriteableBitmap src,i ...

  9. Win8 Metro(C#)数字图像处理--2.45图像雾化效果算法

    原文:Win8 Metro(C#)数字图像处理--2.45图像雾化效果算法 [函数名称]   图像雾化         AtomizationProcess(WriteableBitmap src,i ...

随机推荐

  1. [Angular] Angular CLI

    Create an app with routing config: ng new mynewapp --routing If you want to generate a new module wi ...

  2. php标准库中的优先队列SplPriorityQueue怎么使用?(继承)

    php标准库中的优先队列SplPriorityQueue怎么使用?(继承) 一.总结 1.new对象,然后通过insert方法和extract方法来使用,top方法也很常用. 2.类的话首先想到继承, ...

  3. Linux删除非空目录

    Linux下如何删除非空目录   这个问题很basic,不过还是困扰了我一段时间.(这里主要讨论的是命令行模式下)我本来觉得应该使用命令 rmdir但是发现它无法删除非空的目录.后来发现了原来应该使用 ...

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

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

  5. Spring学习笔记之六(数据源的配置)

    1.前言 上一篇博客分析了,Spring中实现AOP的两种动态代理的机制,以下这篇博客.来解说一下Spring中的数据源的配置.  2.DAO支持的模板类 Spring提供了非常多关于Dao支持的模板 ...

  6. js进阶 9 js操作表单知识点总结

    js进阶 9 js操作表单知识点总结 一.总结 一句话总结:熟记较常用的知识点,对于一些不太常用的知识点可以在使用的时候查阅相关资料,在使用和练习中去记忆. 1.表单中学到的元素的两个对象集合石什么? ...

  7. CocoaPods详解之(三)----制作篇

    CocoaPods详解之----制作篇 作者:wangzz 原文地址:http://blog.csdn.net/wzzvictory/article/details/20067595 转载请注明出处 ...

  8. 【bzoj3555】[Ctsc2014]企鹅QQ 简单哈希

    传送门 题目分析 题意即求有多少对字符串只相差一个字符,枚举删除每个字符后的哈希, 看有多少相等即可. 比如有如下字符串:$Sd123$,其中S部分的哈希值为H,删除的是d,则原字符串的哈希值为$$( ...

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

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

  10. 【codeforces 534B】Covered Path

    [题目链接]:http://codeforces.com/contest/534/problem/B [题意] 你在t秒内可以将车的速度任意增加减少绝对值不超过d; 然后要求在一开始车速为v1,t秒之 ...