原文: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. python property属性

    能够检查參数,一直没注意这个语言特性,忽略了非常多细节,感谢 vitrox class Person( object ): def __init__( self, name ): if not isi ...

  2. 【t019】window(单调队列)

    Time Limit: 2 second Memory Limit: 256 MB [问题描述] 给你一个长度为N 的数组,一个长为K的滑动的窗体从最左移至最右端,你只能见到窗口的K个数,每次窗体向右 ...

  3. 64位Oracle11g自带的sqldevelper无法启动

    原因:选择的jdk有问题 解决方法:由于Oracle自带的Sqldeveloper只支持32位的java运行环境,如果本机安装64位jdk,需要手动更改SqlDeveloper路径到32位的jdk即可 ...

  4. idea-环境配置

    显示行号 Settings->Editor->Appearance标签项,勾选Show line numbers 关闭导航 在idea14版本中,上面有个代码导航,show breadcr ...

  5. 排序 —— 希尔排序(Shell sort)

    希尔排序(Shell sort)的名称源于它的发明者 Donald Shell,该算法是冲破二次时间屏障(冒泡和插入排序,基于相邻元素的交换)的第一批算法.希尔排序改进了冒泡和插入排序的相邻元素才进行 ...

  6. database disk image is malformed解决方法

    作者:朱金灿 来源:http://blog.csdn.net/clever101 在Hudson上终止一次Job的运行之后,Hudson在服务器上更新源码出现下图的错误: 查了下英文意思,大意是svn ...

  7. Delphi绘图相关对象(TCanvas对象的方法)

    TCanvas对象的方法 方法 说明 Arc Arc(x1,y1,x2,y2,x3,y3,x4,y4 : Integer); Arc方法在椭圆上画一段弧,椭圆由(x1,y1).(x2,y2) 两点所确 ...

  8. 修改MessageBox的标题的做法

    作者:朱金灿 来源:http://blog.csdn.net/clever101 1.用Win API的::MessageBox或CWnd::MessageBox代替AfxMessageBox. 2. ...

  9. Spring Cloud和Docker搭建微服务平台

    用Spring Cloud和Docker搭建微服务平台 This blog series will introduce you to some of the foundational concepts ...

  10. textarea随内容自动增加高度

    var autoTextarea = function (elem, extra, maxHeight) { extra = extra || 0; var isFirefox = !!documen ...