图像特效---哈哈镜效果滤镜
来源:互联网 发布:怎么攻破一个软件 编辑:程序博客网 时间:2024/04/30 11:47
1,对于哈哈镜效果变换,首先它有两个参数,原点坐标和特效影响因子。
对于图像中的像素点P(x,y),假设原点坐标为X,Y,那么,根据三角函数变换可以得到:
当前像素P的相对坐标cX,cY:
3,由2中得到的新坐标就是像素P(x,y)的映射坐标,图像变换后的像素值就是映射坐标处的像素值。
4,对于半径影响因子k,这里程序中设置为定值100,具体范围自己控制。
以上就是哈哈镜的算法过程,同时我们放上核心代码如下:
//
///
/// Sunset Filter
///
/// Source image.
/// The X position of sun.
/// The Y position of sun.
/// The radius of sun light.
/// The result image.
private Bitmap ConvexFilterProcess(Bitmap srcBitmap, int cenX, int cenY, int radius)
{
Bitmap a = new Bitmap(srcBitmap);
int w = a.Width;
int h = a.Height;
double distance = 0.0;
double dis = 0.0;
if (radius > cenX || radius > cenY)
{
radius = Math.Min(cenX, cenY);
}
Bitmap dst = new Bitmap(w, h);
System.Drawing.Imaging.BitmapData srcData = a.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
System.Drawing.Imaging.BitmapData dstData = dst.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
unsafe
{
byte* pIn = (byte*)srcData.Scan0.ToPointer();
byte* pOut = (byte*)dstData.Scan0.ToPointer();
byte* p = (byte*)srcData.Scan0.ToPointer();
int sWidth = srcData.Stride;
int stride = sWidth - w * 3;
int R, G, B;
int newX = 0, newY = 0;
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
B = pIn[0];
G = pIn[1];
R = pIn[2];
distance = (x - cenX) * (x - cenX) + (y - cenY) * (y - cenY);
dis = Math.Sqrt(distance);
if (distance <= radius * radius && distance > 0)
{
newX = (int)(Math.Floor(dis * (double)(x - cenX) / (double)radius + (double)cenX)+0.5);
newY = (int)(Math.Floor(dis * (double)(y - cenY) / (double)radius + (double)cenY)+0.5);
pOut[0] = (byte)(*(p + newX * 3 + newY * srcData.Stride));
pOut[1] = (byte)(*(p + newX * 3 + 1 + newY * srcData.Stride));
pOut[2] = (byte)(*(p + newX * 3 + 2 + newY * srcData.Stride));
}
else
{
pOut[0] = (byte)B;
pOut[1] = (byte)G;
pOut[2] = (byte)R;
}
pIn += 3;
pOut += 3;
}
pIn += stride;
pOut += stride;
}
a.UnlockBits(srcData);
dst.UnlockBits(dstData);
}
return dst;
}
哈哈镜效果如下:
原图
哈哈镜效果图
程序demo: http://www.zealfilter.com/forum.php?mod=viewthread&tid=53&extra=page%3D2
- 图像特效---哈哈镜效果滤镜
- OpenCV 图像处理 哈哈镜效果
- java 图像特效之放大镜与哈哈镜
- 【图像处理】C#实现哈哈镜效果
- 图像特效---漫画滤镜
- 图像特效---连环画滤镜
- 图像特效---马赛克滤镜
- 图像特效---Wave滤镜
- 图像特效---Swirl滤镜
- 图像特效---水彩画滤镜
- 图像滤镜处理算法:柔化、光照、放大镜、哈哈镜
- 图像滤镜处理算法:柔化、光照、放大镜、哈哈镜
- 图像滤镜处理算法:柔化、光照、放大镜、哈哈镜
- 图像特效---旋转模糊滤镜
- 图像特效---(Instagram)1977滤镜
- 图像特效---怀旧风格滤镜
- 图像特效---暗调滤镜
- 图像特效---Oilpaint油画滤镜
- 大话数据结构——算法
- js中去除空格
- struts2的模型驱动(推荐使用)、属性驱动模式
- java :非递归方法的二叉搜索树,实现部分功能
- 博弈论
- 图像特效---哈哈镜效果滤镜
- 继承关键字:public private protected
- discuz 论坛安装出现空白页
- 第十一周第二项目——圆柱的计算
- leetcode 182. Duplicate Emails
- Dialog样式的Activity
- Ubuntu 10.04 LTS 系统安装
- 最小编辑代价
- MVC简易购物车项目--展示购物车页面