Win8 Metro(C#)数字图像处理--2.61哈哈镜效果
原文:Win8 Metro(C#)数字图像处理--2.61哈哈镜效果
[函数名称]
哈哈镜效果函数 WriteableBitmap DistortingMirrorProcess(WriteableBitmap src, int x, int y)
[算法说明]
哈哈镜效果图像实际上是一种图像形变特效而已,对于这个特效,我们可以通过三角变换来实现。
1,对于哈哈镜效果变换,首先它有两个参数,原点坐标和特效影响因子。
对于图像中的像素点P(x,y),假设原点坐标为X,Y,那么,根据三角函数变换可以得到:
当前像素P的相对坐标cX,cY:
/// <summary>
/// Distorting mirror process.
/// </summary>
/// <param name="src">The source image.</param>
/// <param name="x">Origin of coordinates in x direction.</param>
/// <param name="y">Origin of coordinates in y direction.</param>
/// <returns></returns>
public static WriteableBitmap DistortingMirrorProcess(WriteableBitmap src, int x, int y)////哈哈镜特效
{
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 radius = 0;
double theta = 0;
int tX = 0;
int tY = 0;
int mapX = 0;
int mapY = 0;
int mapR=0;
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
{
tX = i - x;
tY = j - y;
theta = Math.Atan2((double)tY, (double)tX);
radius = (int)Math.Sqrt((double)(tX * tX + tY * tY));
mapR = (int)(Math.Sqrt((double)radius * 100));
mapX = x + (int)(mapR * Math.Cos(theta));
mapY = y + (int)(mapR * Math.Sin(theta));
temp[i * 4 + j * w * 4] = tempMask[mapX * 4 + mapY * w * 4];
temp[i * 4 + 1 + j * w * 4] = tempMask[mapX * 4 + 1 + mapY * w * 4];
temp[i * 4 + 2 + j * w * 4] = tempMask[mapX * 4 + 2 + mapY * w * 4];
}
}
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.61哈哈镜效果的更多相关文章
- Win8 Metro(C#)数字图像处理--2.75灰度图像的形态学算法
		
原文:Win8 Metro(C#)数字图像处理--2.75灰度图像的形态学算法 前面章节中介绍了二值图像的形态学算法,这里讲一下灰度图的形态学算法,主要是公式,代码略. 1,膨胀算法 2,腐蚀算法 3 ...
 - Win8 Metro(C#)数字图像处理--4图像颜色空间描述
		
原文:Win8 Metro(C#)数字图像处理--4图像颜色空间描述  图像颜色空间是图像颜色集合的数学表示,本小节将针对几种常见颜色空间做个简单介绍. /// <summary> / ...
 - Win8 Metro(C#)数字图像处理--3.2图像方差计算
		
原文:Win8 Metro(C#)数字图像处理--3.2图像方差计算 /// <summary> /// /// </summary>Variance computing. / ...
 - Win8 Metro(C#)数字图像处理--3.3图像直方图计算
		
原文:Win8 Metro(C#)数字图像处理--3.3图像直方图计算 /// <summary> /// Get the array of histrgram. /// </sum ...
 - Win8 Metro(C#)数字图像处理--3.4图像信息熵计算
		
原文:Win8 Metro(C#)数字图像处理--3.4图像信息熵计算 [函数代码] /// <summary> /// Entropy of one image. /// </su ...
 - Win8 Metro(C#)数字图像处理--3.5图像形心计算
		
原文:Win8 Metro(C#)数字图像处理--3.5图像形心计算 /// <summary> /// Get the center of the object in an image. ...
 - Win8 Metro(C#)数字图像处理--2.73一种背景图像融合特效
		
原文:Win8 Metro(C#)数字图像处理--2.73一种背景图像融合特效 /// <summary> /// Image merge process. /// </summar ...
 - Win8 Metro(C#)数字图像处理--3.1图像均值计算
		
原文:Win8 Metro(C#)数字图像处理--3.1图像均值计算 /// <summary> /// Mean value computing. /// </summary> ...
 - Win8 Metro(C#)数字图像处理--2.74图像凸包计算
		
原文:Win8 Metro(C#)数字图像处理--2.74图像凸包计算 /// <summary> /// Convex Hull compute. /// </summary> ...
 
随机推荐
- Ntp配置文件详解
			
1. http://www.ine.com/resources/ntp-authentication.htm 2. http://blog.chinaunix.net/uid-773723-id-16 ...
 - USACO--2.1The Castle
			
思路:这个题目难在建图,開始的时候我想把每一个房间没有墙的面求出来,然后再和他邻近的房间加上一条边进行建图,后面发现要通过题目给定的条件求出房间那个面没有墙是十分困难的:后面參考了别人的思路,我们记录 ...
 - IT增值服务客户案例(二):河南郑州大四实习生,职业规划和项目开发指导
			
客户整体情况,河南郑州大四在校学生,目前在企业实习,从事Java开发工作.有一定的项目开发经验,对Java周边技术有基本的理解. 客户购买的是"拜师学艺"服务,按月付款. 经过多次 ...
 - [NPM] Run a set of similar npm scripts with a wildcard
			
In this lesson we will run a set of scripts that are grouped together with a wildcard using the npm- ...
 - TensorFlow 学习(十三)—— tf.app.flags
			
flags = tf.app.flags FLAGS = flags.FLAGS flags.DEFINE_integer('num_hidden_layers', 3, 'number of hid ...
 - Android如何获得系统版本
			
如何获得Android系统版本 项目移植中,遇到需要区分不同系统版本的问题.于是查找相关方法如下: android.os.Build类提供了当前系统信息. 可用if (Build.VERSION.SD ...
 - 深度学习实践指南(六)—— ReLU(前向和后向过程)
			
def relu_forward(x): out = x * (x > 0) # * 对于 np.ndarray 而言表示 handmard 积,x > 0 得到的 0和1 构成的矩阵 r ...
 - 机器审核图片学习(1)pornDetector
			
a) https://github.com/bakwc/PornDetector 封装了两个库,opencv与scikit-learn 另外一种法师封装了opencv与tensorflow
 - message contains no documents  code:13066 mongdb数据库报的错误
			
message contains no documents code:13066stackoverflow上面的回答是: What version of the C# driver are you ...
 - CUDA二维纹理内存+OpenCV图像滤波
			
CUDA和OpenCV混合编程,使用CUDA的纹理内存,实现图像的二值化以及滤波功能. #include <cuda_runtime.h> #include <highgui/hig ...