原文: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. Net Core 下 Newtonsoft.Json 转换字符串 null 替换成string.Empty

    原文:Net Core 下 Newtonsoft.Json 转换字符串 null 替换成string.Empty public class NullToEmptyStringResolver : De ...

  2. 图标插件--jqplot实现柱状图及饼图,表盘图演示样例

    柱状图 在jqPlot图表插件使用说明(一)中,我们已经能够通过jqPlot绘制出比較简单的线形图.通过查看源码.我们也能够看出,线形图是jqPlot默认的图表类型: /** * Class: Ser ...

  3. Oracle 11g对依赖的推断达到字段级

    在Oracle 10g下,推断依赖性仅仅达到了对象级.也就是说存储过程訪问的对象一旦发生了变化.那么Oracle就会将存储过程置为INVALID状态.所以在为表做了DDL操作后.须要把存储过程又一次进 ...

  4. 虚拟机的ip网络设置的选择

    首先看一下vm的这几个设置 通过截图可以基本看到几个网络设置的区别,具体体现在虚拟机装好以后,网络设置会多出两个适配器,不同模式会分配不同区段的ip,需要固定时主要区段要求 所以总结一下 1.桥连,适 ...

  5. iOS项目中所有icon的尺寸以及命名

    一般icon以下几个: Icon.png – 57×57 iPhone (ios5/6) Icon@2x.png – 114×114 iPhone Retina (ios5/6) Icon-72.pn ...

  6. CodeForces 659E New Reform (图的遍历判环)

    Description Berland has n cities connected by m bidirectional roads. No road connects a city to itse ...

  7. 【noip模拟】德充符

    时间限制:2s 内存限制:512MB [题目描述] 申徒嘉和郑子产都是伯昏无人的学生,子产因为申徒嘉是残疾人,非常看不起他,于是想要刁难他. 子产给了申徒嘉 n个数 a1,a2...an. 现在他要求 ...

  8. node与webpack的process.env.NODE_ENV

    先看两篇文章 1.前端工程项目的NODE_ENV 2. Node 环境变量 process.env.NODE_ENV 之webpack应用 3.process.env.NODE_ENV 下面全部是在w ...

  9. Android studio怎么创建Android虚拟机?

    进行Android studio中进行开发app应用的情况,如果在进行调式app的应用的情况下,没有真机手机机器是没有办法调式的,那么只能通过Android studio中sdk提供虚拟机进行调式ap ...

  10. WPF 开发自动开机启动程序

    原文:WPF 开发自动开机启动程序 本文告诉大家如何在 WPF 开发一个可以自动启动的程序 本文使用的自动开机启动方法是通过快捷方式放在启动文件夹的方式. 创建快捷方式 /// <summary ...