原文: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. C++ 工具类 —— 词条类(Entry)

    Entry 以键值对(key-value pair)的形式定义. template <typename K, typename V> struct Entry{ K key; V valu ...

  2. iptables 重启系统生效

    1. 重启系统生效 开启: chkconfig iptables on 关闭: chkconfig iptables off   2. 即时生效,重启后失效 开启: service iptables ...

  3. 【codeforces 752F】Santa Clauses and a Soccer Championship

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

  4. 三种方式使得iOS应用能够在后台进行数据更新和下载

    三种方式使得iOS程序即使在关闭或崩溃的情况下也能够在后台持续进行一些任务,比如更新程序界面快照,下载文件等.这三个方法分别是 Background Fetch,Remote Notification ...

  5. 【codeforces 768C】Jon Snow and his Favourite Number

    [题目链接]:http://codeforces.com/contest/768/problem/C [题意] 给你n个数字; 让你每次把这n个数字排序; 然后对奇数位的数字进行异或操作,然后对新生成 ...

  6. 如何通过submit提交form表单获取后台传来的返回值

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/qq_34651764/article/details/76373846 小伙伴是不是遇到过这样的问题 ...

  7. jdk8-collect

    toMap 常用方式 public Map<Long, String> getIdNameMap(List<Account> accounts) { return accoun ...

  8. Android app 第三方微信支付接入详解

    微信支付做了好几遍了,都没有出现什么棘手的问题,下面一一为大家分享一下,欢迎吐槽. 还是老样子,接入微信的支付要第一步添加微信支付官方的包libammsdk.jar 首先就处理略坑的一个问题,app应 ...

  9. 【Struts2学习笔记(4)】指定需要Struts 2请求后缀的常量定义复杂的过程

    一.指定需要Struts 2请求后缀处理 我们是在违约前.action后缀访问Action. 事实上默认后缀是通过不断"struts.action.extension"进行更改.例 ...

  10. Android平台第三方应用分享到微信开发

    一.申请APPID 微信公共平台和微博分享一样,也需要申请一个ID,来作为调起微信.分享到微信的唯一标识. 申请微信APPID可以到微信平台http://open.weixin.qq.com/app/ ...