PhotoShop算法实现高级篇--挤压特效(三十六)
来源:互联网 发布:算法4和算法导论哪个好 编辑:程序博客网 时间:2024/05/22 18:47
PhotoShop算法实现高级篇--挤压特效(三十六)
kezunhai@gmail.com
http://blog.csdn.net/kezunhai
在Apple本本自带的摄像头里有挤压的功能,带小侄子玩的时候乐得嘴都合不拢。其实挤压效果的时候先是将图像向内挤压,挤压的过程产生压缩变形,从而形成的效果。挤压效果的实现是通过数学极坐标的形式,将当前像素、图像中心店和过中心点的水平线这三要素画出的一个极坐标,然后根据指定的挤压度,在当前点与中心点所连的直线上映射出一个像素点,此像素点即为目标像素点。
先上一张图,美女(效果似曾相似不?):
算法实现比较简单,如下:
// degree:挤压幅度(1-32)void PhotoShop::Pinch(Mat& img, Mat& dst, int degree){if (degree<1 ) degree = 1;if ( degree> 32) degree = 32;if ( dst.empty())dst.create(img.rows, img.cols, img.type());dst = cv::Scalar::all(0);int chns = img.channels();int height = img.rows;int width = img.cols;int midX = width/2;int midY =height/2;int i, j, k;int X, Y, offsetX, offsetY;double radian, radius; //弧和半径for ( i=0; i<height; i++){for ( j=0; j<width; j++){offsetX = j-midX;offsetY = i- midY;radian = atan2((double)offsetY, (double)offsetX);// 半径radius = sqrtf((float)(offsetX*offsetX + offsetY*offsetY));radius = sqrtf(radius)*degree;X = (int)(radius*cos(radian))+midX;Y = (int)(radius*sin(radian))+midY;if ( X<0 ) X = 0;if ( X>= width) X = width - 1;if ( Y<0 ) Y = 0;if ( Y>=height) Y = height -1;for ( k=0; k<chns; k++){setPixel(dst, i,j, k, getPixel(img, Y, X, k));}}}}再来一张凤姐的老公:
再来个丑的(看你还跟鬼子混不):
哈哈,喜庆哈,丑你没商量。
凶器没了~?~
作者:kezunhai 出处:http://blog.csdn.net/kezunhai 欢迎转载或分享,但请务必声明文章出处。
0 0
- PhotoShop算法实现高级篇--挤压特效(三十六)
- PhotoShop算法实现高级篇--色彩特效(三十五)
- PhotoShop算法实现高级篇--畸变特效(三十七)
- PhotoShop算法实现高级篇-剪纸艺术滤镜(三十二)
- PhotoShop算法实现高级篇-素描(三十三)
- PhotoShop算法实现高级篇--连环画(三十四)
- PhotoShop算法实现高级篇--马赛克(三十八)
- Android特效开发(可伸缩View带互相挤压效果)进阶篇
- 图像特效之挤压特效
- PhotoShop算法实现--色彩通道(九)
- PhotoShop算法实现--直方图(十)
- PhotoShop算法实现-- 图像平移(十五)
- PhotoShop算法实现--图像缩放(十八)
- PhotoShop算法实现--图像旋转(十九)
- 图像特效---挤压(Pinch)滤镜
- 玩无限消乐的设计示例(高级篇)直线特效算法
- 玩无限消乐的设计示例(高级篇)炸弹特效算法
- 玩无限消乐的设计示例(高级篇)灭绝特效算法
- 小记
- 本体语言OWL基本知识
- 一种控制进程CPU利用率的方法
- Linux CentOS 配置IP
- 教你如何对齐!
- PhotoShop算法实现高级篇--挤压特效(三十六)
- C#制作闪动的窗体
- 一些注意事项
- popupwindow 透明实现activity使用帮助
- Centos 配置eth0 提示Device does not seem to be present
- 深入理解Java虚拟机笔记---类索引,父类索引,接口索引集合
- Hadoop学习<二>--HDFS文件系统操作方式
- 【后缀数组】【poj 3693】Maximum repetition substring
- oracle数据库监听例程blocked的处理