// 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
orthogonal to polar 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; e=(float)width/(float)height;
R=(float)height/2.0; Point Center(width/2, height/2); float R1, 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++)
{ theta=atan2((float)((Center.y-y)*e), (float)(x-Center.x)); if ((Center.y-y)<=0) theta=theta+2*pi; R1=((Center.y-y)/sin(theta));
new_y=R1*height/R;
new_x=theta*width/(2*pi); 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 滤镜算法之平面坐标到极坐标的变换的更多相关文章

  1. OpenCV——PS 滤镜算法之极坐标变换到平面坐标

    // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...

  2. OpenCV——PS滤镜算法之 球面化 (凹陷效果)

    // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...

  3. OpenCV——PS滤镜算法之Spherize 球面化(凸出效果)

    // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...

  4. OpenCV——PS滤镜算法之 Ellipsoid (凹陷)

    // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...

  5. OpenCV——PS滤镜算法之 Ellipsoid (凸出)

    // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...

  6. OpenCV——PS 滤镜, 浮雕效果

    具体的算法原理可以参考: PS 滤镜, 浮雕效果 // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITH ...

  7. OpenCV——PS 滤镜, 曝光过度

    算法原理可以参考: PS 滤镜,曝光过度 #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include <io ...

  8. PS 滤镜算法原理——染色玻璃

    %%%% 完成PS 中的染色玻璃滤镜特效 clc; clear all; close all; Image=imread('4.jpg'); Image=double(Image); Gray_Ima ...

  9. PS 滤镜算法原理 ——马赛克

    % method : 利用邻域的随意一点取代当前邻域全部像素点 %%%% mosaic clc; clear all; addpath('E:\PhotoShop Algortihm\Image Pr ...

随机推荐

  1. VueJS自定义全局和局部指令

    除了默认设置的核心指令( v-model 和 v-show ), Vue 也允许注册自定义指令. 使用directive自定义全局指令 下面我们注册一个全局指令 v-focus, 该指令的功能是在页面 ...

  2. C语言 结构体篇

    结构体:是一种构造类型 它是由若干成员组成的 其中每一个成员都可以是一个基本数据类型或者又是一个构造类型 定义结构体变量后,系统就会为其自动分配内存 为了便于更大的程序便于修改和使用  常常将结构体类 ...

  3. mysql中的类型转换和精确位数

    select round(123.5); 四舍五入 select floor(123.5);取整数部分 select ceil(123.5);四舍五入

  4. jquery插件函数传参错误

    1.jquery传参通过json,可能的错误是,参数中的结束符写成了;

  5. xml 操作

    /////////////////////////////////jaxp对xml文档进行解析/////////////////////////////////////////// 要操作的xml文件 ...

  6. 使用jquery改动表单的提交地址

    基本思路: 通过使用jquery选择器得到相应表单的jquery对象,然后使用attr方法改动相应的action 演示样例程序一: 默认情况下,该表单会提交到page_one.html 点击butto ...

  7. java 白皮书的关键术语

    [0]README 0.1) 本文转自 core java volume 1,仅供了解,所谓爱屋及乌嘛: 0.2) java的设计者编写了颇有影响力的白皮书,用来解释设计的初衷以及完成的情况,并发布了 ...

  8. PHP进阶知识

    关于PHP程序员技术职业生涯规划:http://rango.swoole.com/ Micro Service Framework For PHP:https://github.com/pinguo/ ...

  9. python 中读取excel

    第一步:  先下载一个xlrd 包 # pip install xlrd import xlrd from datetime import date, datetime file = '学生信息表.x ...

  10. npm 全局配置放在c盘/用户/当前用户/目录下

    prefix=D:\Users\Ed\AppData\Roaming\nodejs\npm-globalcache=D:\Users\Ed\AppData\Roaming\npm-cacheregis ...