OpenCV——PS滤镜算法之 球面化 (凹陷效果)
// define head function
#ifndef PS_ALGORITHM_H_INCLUDED
#define PS_ALGORITHM_H_INCLUDED
#include <iostream>
#include <string>
#include "cv.h"
#include "highgui.h"
#include "cxmat.hpp"
#include "cxcore.hpp"
#include "math.h"
using namespace std;
using namespace cv;
void Show_Image(Mat&, const string &);
#endif // PS_ALGORITHM_H_INCLUDED
#include "PS_Algorithm.h"
#include <time.h>
using namespace std;
using namespace cv;
#define pi 3.1415926
int main()
{
string Img_name("4.jpg");
Mat Img;
Img=imread(Img_name);
Mat Img_out(Img.size(), CV_8UC3);
Img.copyTo(Img_out);
int width=Img.cols;
int height=Img.rows;
float R;
float e;
float a,b;
float alpha=0.75;
float K=pi/2;
a=height/2.0; b=width/2.0;
e=(float)width/(float)height;
R=std::min(a,b);
Point Center(width/2, height/2);
float radius,r0,Dis,new_x, new_y;
float p,q,x1,y1,x0,y0;
float theta;
for (int y=0; y<height; y++)
{
for (int x=0; x<width; x++)
{
y0=Center.y-y;
x0=x-Center.x;
Dis=x0*x0+y0*y0;
r0=sqrt(Dis);
if(Dis<R*R)
{
theta=atan(y0/(x0+0.00001));
if(x0<0) theta=theta+pi;
radius=R*sin(r0/R*K);
radius=(radius-r0)*(alpha)+r0;
new_x=radius*cos(theta);
new_y=radius*sin(theta);
new_x=Center.x+new_x;
new_y=Center.y-new_y;
if(new_x<0) new_x=0;
if(new_x>=width-1) new_x=width-2;
if(new_y<0) new_y=0;
if(new_y>=height-1) new_y=height-2;
x1=(int)new_x;
y1=(int)new_y;
p=new_x-x1;
q=new_y-y1;
for (int k=0; k<3; k++)
{
Img_out.at<Vec3b>(y, x)[k]=(1-p)*(1-q)*Img.at<Vec3b>(y1, x1)[k]+
(p)*(1-q)*Img.at<Vec3b>(y1,x1+1)[k]+
(1-p)*(q)*Img.at<Vec3b>(y1+1,x1)[k]+
(p)*(q)*Img.at<Vec3b>(y1+1,x1+1)[k];
}
}
}
}
Show_Image(Img_out, "out");
imwrite("Out.jpg", Img_out);
waitKey();
}
// define the show image
#include "PS_Algorithm.h"
#include <iostream>
#include <string>
using namespace std;
using namespace cv;
void Show_Image(Mat& Image, const string& str)
{
namedWindow(str.c_str(),CV_WINDOW_AUTOSIZE);
imshow(str.c_str(), Image);
}
原图
效果图
OpenCV——PS滤镜算法之 球面化 (凹陷效果)的更多相关文章
- OpenCV——PS滤镜算法之 Ellipsoid (凹陷)
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...
- OpenCV——PS滤镜算法之Spherize 球面化(凸出效果)
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...
- OpenCV——PS 滤镜算法之极坐标变换到平面坐标
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...
- OpenCV——PS 滤镜算法之平面坐标到极坐标的变换
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...
- OpenCV——PS滤镜算法之 Ellipsoid (凸出)
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...
- OpenCV——PS 滤镜, 浮雕效果
具体的算法原理可以参考: PS 滤镜, 浮雕效果 // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITH ...
- OpenCV——PS 滤镜, 曝光过度
算法原理可以参考: PS 滤镜,曝光过度 #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include <io ...
- PS 滤镜算法原理——碎片效果
%%% Fragment %%% 对原图做四个方向的平移,然后对平移的结果取平均 %%% 碎片效果 clc; clear all; Image=imread('4.jpg'); Image=doubl ...
- OpenCV——PS滤镜之 波浪效果 wave
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...
随机推荐
- python 和 mysql连接
python 和 mysql连接 虫师教程:http://www.cnblogs.com/fnng/p/3565912.html 其他教程pymysql:http://www.cnblogs.com/ ...
- SpringMVC请求流程与原理分析
SpringMVC的工作原理图: SpringMVC流程 1. 用户发送请求至前端控制器DispatcherServlet. 2. DispatcherServlet收到请求调用HandlerMa ...
- 贷前系统ElasticSearch实践总结
贷前系统负责从进件到放款前所有业务流程的实现,其中涉及一些数据量较大.条件多样且复杂的综合查询,引入ElasticSearch主要是为了提高查询效率,并希望基于ElasticSearch快速实现一个简 ...
- hadoop修改主机名遇到的坑
正确的修改方式 CentOS修改主机名(hostname) 需要修改两处:一处是/etc/sysconfig/network,另一处是/etc/hosts,只修改任一处会导致系统启动异常.首先切换到r ...
- golang生成随机函数的实现
golang生成随机数可以使用math/rand包, 示例如下: package main import ( "fmt" "math/rand" ) func ...
- JavaScript -- 没事看看
@.delete 原文:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/delete
- java 常用设计模式(转载)
http://www.cnblogs.com/hnrainll/archive/2011/12/29/2305582.html 设计模式:一个程序员对设计模式的理解:“不懂”为什么要把很简单的东西搞得 ...
- Makefile浅尝
[0]README makefile定义: 一个工程中的源文件不计其数,其按类型.功能.模块分别放在若干个目录中,makefile定义了一系列的规则来指定,哪些文件需要一先编译,哪些文件需要后编译,哪 ...
- Cauchy sequence Hilbert space 希尔波特空间的柯西序列
http://mathworld.wolfram.com/HilbertSpace.html A Hilbert space is a vector space with an inner prod ...
- 远程服务器上的weblogic项目管理(四)filelock not found错误解决方法
重启weblogic时如果有残余进程没有kill,启动时便可能会造成filelock not found,文件锁未找到错误,解决方法如下: 删掉Domain下的*.lok文件:(如果不熟悉文件路径推荐 ...