OpenCV——PS滤镜算法之Spherize 球面化(凸出效果)
// 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,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;
if(Dis<R*R)
{
theta=atan(y0/(x0+0.00001));
if(x0<0) theta=theta+pi;
radius=asin(sqrt(Dis)/R)*R/K;
radius=(sqrt(Dis)-radius)*(1-alpha)+radius;
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];
}
}
}
}
Img_out=Img_out;
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滤镜算法之Spherize 球面化(凸出效果)的更多相关文章
- 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 滤镜算法之极坐标变换到平面坐标
// 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 滤镜——(扭曲)球面化 Spherize
%%%% Spherize clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorit ...
- PS 滤镜算法原理——染色玻璃
%%%% 完成PS 中的染色玻璃滤镜特效 clc; clear all; close all; Image=imread('4.jpg'); Image=double(Image); Gray_Ima ...
随机推荐
- select设置innerHMTL
select控件在标准浏览器下可以直接innerHTML设置内容,IE则不行. HTML结构: <form name="form1"> <select name= ...
- robotframework使用之RIDE的底部的日志没显示怎么办?
问题:RIDE的底部的日志没显示怎么办? 解决办法:在Python27的安装路径下D:\Python27\Lib\site-packages\robotide\contrib\testrunner下的 ...
- Ubuntu12安装RobotFramework
安装Python Ubuntu默认已安装 安装pip wget https://bootstrap.pypa.io/get-pip.py python get-pip.pysudo apt-get i ...
- hdu4857 & BestCoder Round #1 逃生(拓扑逆排序+优先队列)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=4857 ----------------------------------------------- ...
- sprint3 【每日scrum】 TD助手站立会议第五天
站立会议 组员 昨天 今天 困难 签到 刘铸辉 (组长) 通过网上的介绍懂得了闹钟的添加和工作原理,然后加入了震动效果 在添加日程类型处添加了选择闹钟间隔多长时间相应,并写了闹钟运行的类 广播协议也弄 ...
- Laravel 5.4的本地化
简介 Laravel 的本地化功能提供方便的方法来获取多语言的字符串,让你的网站可以简单的支持多语言. 语言包存放在 resources/lang 目录下的文件里.在此目录中应该有应用对应支持的语言并 ...
- 双向数据绑定---AngularJS的基本原理学习
Angular JS (Angular.JS) 是一组用来开发Web页面的框架.模板以及数据绑定和丰富UI组件.它支持整个开发进程,提供web应用的架构,无需进行手工DOM操作. AngularJS非 ...
- 《textanalytics》课程简单总结(2):topic mining
coursera上的公开课<https://www.coursera.org/course/textanalytics>系列,讲的很不错哦. 1."term as topic&q ...
- u-boot 学习系列 1 - SPL
u-boot这个东西从自我N年前使用到现在,变化好多,今天开始重新研究下,本系列的研究都是基于BeagleBoneBlack(bbb)开发板和 u-boot v201801版本的. SPL介绍 在源代 ...
- 设置jvm运行内存
:1.右击项目—Bulid Path—Configure Build Path—Libraries,找到JRE System Libraary[Sun JDK 1.6.0_13],选中JRE Syst ...