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
/*
This program will transform from the
polar to orthogonal coordinate.
*/
#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);
Show_Image(Img, Img_name);
Mat Img_in(Img.size(), CV_32FC3);
Img.convertTo(Img_in, CV_32FC3);
// Show_Image(Img_in, "in");
Mat Img_out(Img_in.size(), CV_32FC3);
Img_in.convertTo(Img_out, CV_32FC3);
int width=Img_in.cols;
int height=Img_in.rows;
float R;
float e;
float a,b;
e=(float)width/(float)height;
R=(float)height/2.0;
a=(float)width/2.0;
b=R;
Point Center(width/2, height/2);
float R1,R2,new_x, new_y;
float p,q,x1,y1;
float theta;
for (int y=0; y<height; y++)
{
for (int x=0; x<width; x++)
{
R1=y*R/height;
R2=R1*e;
theta=x*2*pi/width;
new_y=Center.y-R1*sin(theta);
new_x=Center.x+R2*cos(theta);
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<Vec3f>(y, x)[k]=(1-p)*(1-q)*Img_in.at<Vec3f>(y1, x1)[k]+
(p)*(1-q)*Img_in.at<Vec3f>(y1,x1+1)[k]+
(1-p)*(q)*Img_in.at<Vec3f>(y1+1,x1)[k]+
(p)*(q)*Img_in.at<Vec3f>(y1+1,x1+1)[k];
}
}
}
Img_out=Img_out/255.0;
Show_Image(Img_out, "out");
imwrite("Out.jpg", Img_out*255);
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 滤镜算法之平面坐标到极坐标的变换
// 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滤镜算法之Spherize 球面化(凸出效果)
// 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滤镜算法之 Ellipsoid (凸出)
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...
- Python: PS 滤镜-- 极坐标变换到平面坐标
本文用 Python 实现 PS 中的一种滤镜 极坐标变换到平面坐标,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/de ...
- 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 ...
- OpenCV图像变换二 投影变换与极坐标变换实现圆形图像修正
投影变换 在放射变换中,物体是在二维空间中变换的.如果物体在三维空间中发生了旋转,那么这种变换就成为投影变换,在投影变换中就会出现阴影或者遮挡,我们可以运用二维投影对三维投影变换进行模块化,来处理阴影 ...
随机推荐
- 开发ActiveX控件调用另一个ActiveX系列1——开发一个MFC ActiveX控件
ActiveX开发的教程有很多,我也从中受益匪浅,例如以下这几篇: 基本教程:http://www.cnblogs.com/guenli/articles/1629915.html 注意事项:http ...
- jQuery的Pagenation分页插件。
插件简介 此jQuery插件为Ajax分页插件,一次性加载,故分页切换时无刷新与延迟,如果数据量较大不建议用此方法,因为加载会比较慢. 原插件CSS不太合理,使用浮动,故无法方便实现左右方向的定位,且 ...
- python爬虫,从hao123爬取网址信息
最近研究python的爬虫,小小程序,拿下来分享,本人使用python3.7,纯粹兴趣爱好,希望能帮助大家激发兴趣.从hao123,爬取各种网址信息,代码如下. import urllib.reque ...
- javascript onclick中post提交
对post提交进行封装: function post(URL, PARAMS) { var temp = document.createElement("form"); temp. ...
- 【Python】用Python打开IE、谷歌等浏览器报错及解决办法
以IE浏览器为例: 当Python Shell输入下面代码时: >>> # coding=utf-8 >>> from selenium import webdri ...
- eclipse maven安装配置
下载在Apache下载Maven,下载地址:http://maven.apache.org/download.html,在win7下载文件为:apache-maven-3.1.0-bin.zip. ...
- linux jdk 安装另一种方法
linux 7.2 安装 jdk方法: (1). 以root用户登录linux系统, 应用Xmanager把文件拷贝到linux 系统的根目录. (2). 进入opt/software建立jvm文件夹 ...
- win10 64位 安装TensorFlow
.由于之前安装的是python2.7 ,tensorflow在windows下必须要python3 网上查了一下有三种方法2版本共存 1.不用Anaconda windows 安装python2 与p ...
- 使用 Django1.11搭建blog项目
使用Django搭建blog项目 简单设置: http://blog.csdn.net/w_e_i_/article/details/70761604 模板渲染: http://blog.csdn.n ...
- Tomcat Server 配置
Tomcat报错: The JRE could not be found. Edit the server and change the JRE location. EClipse -> win ...