原文:Win8 Metro(C#)数字图像处理--2.73一种背景图像融合特效

        /// <summary>
/// Image merge process.
/// </summary>
/// <param name="bacImage">The background image.</param>
/// <param name="dstImage">The source image.</param>
/// <param name="k">One parameter, from 0 to 1.</param>
/// <returns></returns>
public static WriteableBitmap ImageMerge(WriteableBitmap bacImage, WriteableBitmap dstImage, double k)
{
if (bacImage != null && dstImage != null)
{
int w = dstImage.PixelWidth;
int h = dstImage.PixelHeight;
int sw = bacImage.PixelWidth;
int sh = bacImage.PixelHeight;
WriteableBitmap srcImage = new WriteableBitmap(w, h);
byte[] dstValue = dstImage.PixelBuffer.ToArray();
byte[] bacValue = bacImage.PixelBuffer.ToArray();
byte[] tempValue = new byte[dstValue.Length];
int r = 0, g = 0, b = 0, R = 0, G = 0, B = 0;
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
int tx = x % sw;
int ty = y % sh;
b = bacValue[tx * 4 + ty * w * 4];
g = bacValue[tx * 4 + 1 + ty * w * 4];
r = bacValue[tx * 4 + 2 + ty * w * 4];
B = dstValue[x * 4 + y * w * 4];
G = dstValue[x * 4 + 1 + y * w * 4];
R = dstValue[x * 4 + 2 + y * w * 4];
double xr = 0.0, xb = 0.0, xg = 0.0;
xr = ((double)r - ((double)R - (double)k * 255.0)) / (2.0 * 255.0 * k);
xg = ((double)g - ((double)G - (double)k * 255.0)) / (2.0 * 255.0 * k);
xb = ((double)b - ((double)B - (double)k * 255.0)) / (2.0 * 255.0 * k);
tempValue[x * 4 + y * w * 4] = (byte)(255.0 * (1.0 - 3.0 * xb * xb + 2.0 * xb * xb * xb));
tempValue[x * 4 + 1 + y * w * 4] = (byte)(255.0 * (1.0 - 3.0 * xg * xg + 2.0 * xg * xg * xg));
tempValue[x * 4 + 2 + y * w * 4] = (byte)(255.0 * (1.0 - 3.0 * xr * xr + 2.0 * xr * xr * xr));
}
}
Stream sTemp = srcImage.PixelBuffer.AsStream();
sTemp.Seek(0, SeekOrigin.Begin);
sTemp.Write(tempValue, 0, w * 4 * h);
return srcImage;
}
else
{
return null;
}
}

最后,分享一个专业的图像处理网站(微像素),里面有很多源代码下载:

Win8 Metro(C#)数字图像处理--2.73一种背景图像融合特效的更多相关文章

  1. Win8 Metro(C#)数字图像处理--2.59 P分位法图像二值化

    原文:Win8 Metro(C#)数字图像处理--2.59 P分位法图像二值化  [函数名称]   P分位法图像二值化 [算法说明]   所谓P分位法图像分割,就是在知道图像中目标所占的比率Rat ...

  2. Win8 Metro(C#)数字图像处理--2.57一维最大熵法图像二值化

    原文:Win8 Metro(C#)数字图像处理--2.57一维最大熵法图像二值化  [函数名称] 一维最大熵法图像二值化WriteableBitmap EntropymaxThSegment(Wr ...

  3. Win8 Metro(C#)数字图像处理--2.75灰度图像的形态学算法

    原文:Win8 Metro(C#)数字图像处理--2.75灰度图像的形态学算法 前面章节中介绍了二值图像的形态学算法,这里讲一下灰度图的形态学算法,主要是公式,代码略. 1,膨胀算法 2,腐蚀算法 3 ...

  4. Win8 Metro(C#)数字图像处理--4图像颜色空间描述

    原文:Win8 Metro(C#)数字图像处理--4图像颜色空间描述  图像颜色空间是图像颜色集合的数学表示,本小节将针对几种常见颜色空间做个简单介绍. /// <summary> / ...

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. 【转】priority_queue的用法

    http://www.cnblogs.com/flyoung2008/articles/2136485.html priority_queue调用 STL里面的 make_heap(), pop_he ...

  2. 【u024】没有上司的舞会

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 某大学有N个职员,编号为1~N.他们之间有从属关系,也就是说他们的关系就像一棵以校长为根的树,父结点就 ...

  3. [Angular] Using directive to create a simple Credit card validator

    We will use 'HostListener' and 'HostBinding' to accomplish the task. The HTML: <label> Credit ...

  4. 使用Toolbar + DrawerLayout快速实现高大上菜单侧滑

    如果你有在关注一些遵循最新的Material Design设计规范的应用的话(如果没有,假设你有!),也许会发现有很多使用了看起来很舒服.很高大上的侧滑菜单动画效果,示例如下(via 参考2): 今天 ...

  5. 数据序列化之protobuf

    数据序列化之protobuf 很多时候需要将一些数据打包,就是把这些数据搞在一起,方便处理.最常见的情况就是把需要传输的数据,当然数据不止一条,打包成一个消息,然后发送出去,接收端再以一定的规则接收并 ...

  6. 安装 Visual Studio,连接中国区 Azure

    中国数据中心 目前,中国区 Azure 有两个数据中心,在位置字段中显示为“中国北部”和“中国东部”. 在 Azure 上创建应用程序的区别 在中国区 Azure 上开发应用程序与在境外 Azure ...

  7. 对raid几个技术的简单理解

    磁盘阵列(Redundant Arrays of Independent Disks,RAID),有“独立磁盘构成的具有冗余能力的阵列”之意,主要体现在两方面: 1.HA 高可用性,也就是冗余 2.L ...

  8. P2P理财友情提示

    最近2年,P2P理财非常火,但是出现的问题也是越来越频繁. 2014年12月,据说有70多家平台出现了问题,加上以前的,一共有300多家了,出现问题的占总比有20%~30%了. 这个真的是非常的可怕. ...

  9. Linux环境编写脚本安装配置JDK,Tomcat,含Tomcat自启动

    mkdir /usr/java mkdir /znywImage cp -f /usr/jdk-7u79-linux-x64.tar.gz /usr/java tomcatPath=/usr/apac ...

  10. C#并发集合

    并发集合   并发集合 1 为什么使用并发集合? 原因主要有以下几点: System.Collections和System.Collections.Generic名称空间中所提供的经典列表.集合和数组 ...