原文: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] Observable.catch error handling in Angular

    import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/map'; import 'rxjs/add/opera ...

  2. 【codeforces 757B】 Bash's Big Day

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

  3. 简单sql部分强化练习题

    简单查询部分sql练习题 -- 选择部门30中的全部职工 select * from emp where deptno = 30; -- 列出全部业务员(CLERK)的姓名,编号,和部门编号 sele ...

  4. jdk 8 lambda表达式以及Predicate接口

    了解lambda之前先了解下什么是函数式接口,函数式接口即接口里必须有一个抽象方法(抽象的方法只能有一个,可以有其他的用default修饰的方法) jdk8里新增了一个@FunctionalInter ...

  5. 获取全局上下文(getApplicationContext)_创建Shared Preference工具类_实现自动登录

    获取全局上下文(getApplicationContext)_创建Shared Preference工具类_实现自动登录 ===========================获取全局上下文(getA ...

  6. Android学习--Assets资源文件读取及AssetManager介绍

    APK安装过程        复制APK安装包到data/app目录下,解压并扫描安装包,把dex文件(Dalvik字节码)保存到dalvik-cache目录,并data/data目录下创建对应的应用 ...

  7. Android菜鸟的成长笔记(18)——绑定本地Service并与之通信

    在上一篇中介绍了Service与Activity的区别及Service两种启动方式中的第一种启动方式startService(). 我们会发现用startService().stopService() ...

  8. 把搜狗输入法词库导入Google拼音输入法

    为PC端Google拼音输入法增加词库 为什么折腾词库 都在说百度.讯飞等输入法上传用户词库,为了安全建议大家使用google输入法之类,话说回来,要想使用智能联想功能是不是就得把你输入习惯放在他的里 ...

  9. Hamcrest 总结

    Junit JUnit框架用一组assert方法封装了一些常用的断言.这些assert方法可以帮我们简化单元测试的编写.这样的话,Junit就可以根据这些断言是否抛出 AssertionFailedE ...

  10. 《Head First 设计模式》学习笔记——命令模式

    在软件系统,"行为请求者"与"行为实施者"通常存在一个"紧耦合".但在某些场合,比方要对行为进行"记录.撤销/重做.事务" ...