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图像变换二 投影变换与极坐标变换实现圆形图像修正
投影变换 在放射变换中,物体是在二维空间中变换的.如果物体在三维空间中发生了旋转,那么这种变换就成为投影变换,在投影变换中就会出现阴影或者遮挡,我们可以运用二维投影对三维投影变换进行模块化,来处理阴影 ...
随机推荐
- iOS UITableViewDelegate && UITableViewDataSource 执行顺序
#pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableV ...
- POJ 3373 Changing Digits
题目大意: 给出一个数n,求m,使得m的长度和n相等.能被k整除.有多个数符合条件输出与n在每位数字上改变次数最小的.改变次数同样的输出大小最小的. 共同拥有两种解法:DP解法,记忆化搜索的算法. ...
- 如何利用Require.Js管理多页面站点文件(译)
英文版地址 最近使用 Require.Js 的时候我发现它确实是一个改善代码管理的一个好方法.我以前发表Backbone类的文章时曾提到过 Require,但此前,我从未在传统的多页面网站内使用到 R ...
- linux uart驱动——相关数据结构以及API(二)
一.核心数据结构 串口驱动有3个核心数据结构,它们都定义在<#include linux/serial_core.h>1.uart_driver uart_driver包 ...
- Centos 7.0防火墙问题
从Centos7开始,自带的防火墙从iptables更改成了firewall.一般在企业环境,出于人力和稳定性考虑,还是用成熟的技术比较稳妥. 以下是关闭firewall的方法 systemctl s ...
- redis数据迁移操作
redis客户端连接命令,分别连接旧环境中的主从redis Src目录下./redis-cli -h IP -p PORT 使用info replication 命令找出主redis使用客户端命令连接 ...
- PHP合并数组+与array_merge的区别
http://www.phpernote.com/php-string/351.html PHP中合并两个数组可以使用+或者array_merge,但这两个还是有区别的 主要区别是当两个或者多个数 ...
- 不同特权级间代码段的跳转{ 门 + 跳转(jmp + call) + 返回(ret) }
[0]写在前面 0.1)我们讲 CPU的保护机制,它是可靠的多任务运行环境所必须的: 0.2) CPU保护机制:分为段级保护 + 页级保护: 0.2.1)段级保护分为:段限长 limit 检查.段类型 ...
- EasyDSS RTMP流媒体服务器的HTTP接口query url的C++实现方法
EasyDSS支持HTTP GET接口访问,我们需要获取url的各种参数信息 比如http://ip:port/action?a=1&b=2&c=3 我们需要知道对应的a.b.c的值 ...
- C#中反射type记录
写代码的时候经常需要使用反射相关的东西例如:分析现有类型自动生成类, 或者为现有的类自动增加一些功能总结了一点点经验以ClassA a; 为例1. 通过typeof(ClassA) 或者 a.Get ...