OpenCV——PS滤镜算法之 Ellipsoid (凸出)
// 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 e;
float a,b, a0, b0, a1,b1;
float alpha=1.0;
float K=pi/2;
a=width/2; b=height/2;
e=(float)width/(float)height;
Point2i Center(width/2, height/2);
float 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;
theta=atan(y0*e/(x0+0.0001));
if(x0<0) theta=theta+pi;
a0=x0/cos(theta);
b0=y0/sin(theta+0.0001);
if(a0/a>1 || b0/b>1) continue;
a1=asin(a0/a)*a/K;
b1=asin(b0/b)*b/K;
a1=(a0-a1)*(1-alpha)+a1;
b1=(b0-b1)*(1-alpha)+b1;
new_x=a1*cos(theta);
new_y=b1*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滤镜算法之 Ellipsoid (凸出)的更多相关文章
- 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滤镜算法之 球面化 (凹陷效果)
// 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 滤镜算法原理——染色玻璃
%%%% 完成PS 中的染色玻璃滤镜特效 clc; clear all; close all; Image=imread('4.jpg'); Image=double(Image); Gray_Ima ...
- PS 滤镜算法原理 ——马赛克
% method : 利用邻域的随意一点取代当前邻域全部像素点 %%%% mosaic clc; clear all; addpath('E:\PhotoShop Algortihm\Image Pr ...
随机推荐
- 更改navigationBar 颜色
if (IS_IOS7()) { /* iOS7 时 Navigation 颜色 */ [[UINavigationBar appearance] setBarTintColor: HexCo ...
- python入门示例程序
该实例是raspi和dsp电机运动控制板的串口uart通信: import serial class SerialHandler(): ''' raspi serial for communicati ...
- win7安装ANT
点击进入ant官网,找到下载选项. 选择下载安装文件.其余的源文件和手册的下载步骤完全相同. 可以下载官网上对应系统的最新版本.也可以在old ant 版本中选择自己需要的版本.笔者需要ant ...
- js监听鼠标点击操作
element.addEventListener('click', function() { /* do stuff here*/ }, false);
- python 怎么启动一个外部命令程序, 并且不阻塞当前进程
http://www.myexception.cn/perl-python/1278887.html http://blog.chinaunix.net/uid-25979788-id-3081912 ...
- 基于 orange(nginx+openresty) + docker 实现微服务 网关功能
摘要 基于 orange(nginx+openresty) + docker 实现微服务 网关功能 ;以实现 docker 独立容器 来跑 独立语言独立环境 在 同一个授权下 运行相关组合程序..年初 ...
- 创建JDBC模板简化代码、JDBC应用的事务管理以及连接池的作用
一.创建JDBC模板简化代码 一个简单的查询.要做这么一大堆事情,并且还要处理异常,我们不防来梳理一下: 1.获取connection 2.获取statement 3.获取resultset 4 ...
- 第一个MapReduce程序——WordCount
通常我们在学习一门语言的时候,写的第一个程序就是Hello World.而在学习Hadoop时,我们要写的第一个程序就是词频统计WordCount程序. 一.MapReduce简介 1.1 MapRe ...
- VBscript 做的设置网卡名称
Set WSHShell=WScript.CreateObject("WScript.Shell") Dim NetcardDescriptionDim NetcardName i ...
- 浅谈JS中的!=、== 、!==、===的用法和区别 JS中Null与Undefined的区别 读取XML文件 获取路径的方式 C#中Cookie,Session,Application的用法与区别? c#反射 抽象工厂
浅谈JS中的!=.== .!==.===的用法和区别 var num = 1; var str = '1'; var test = 1; test == num //tr ...