// 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. UIView属性的动画

    //标记着动画块的开始,第一个参数表示动画的名字,起到标识作用 [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDurat ...

  2. 使用HTML5制作简单的RPG游戏

    很久以前就想着做一个游戏,但什么都不会又不知道从哪里开始,胡乱找来一些书籍和资料结果太深奥看不懂,无奈只能放弃.这一弃就是十多年,倥偬半生,眼看垂垂老矣,还是没能有什么成果. 近年来游戏引擎越来越多, ...

  3. 有一个数组a[N]顺序存放0~N-1,要求每隔两个数删掉一个数,到末尾时循环至开头继续进行,求最后一个被删掉的数的原始下标位置。以8个数(N=7)为例:{0,1,2,3,4,5,6,7},0->1->2(删除)->3->4->5(删除)->6->7->0(删除),如此循环直到最后一个数被删除。

    // ConsoleApplication12.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" // ConsoleApplication1 ...

  4. easyUI中 datagrid 格式化日期

    $('#List').datagrid({ url: '@Url.Action("GetList")', width:SetGridWidthSub(10), methord: ' ...

  5. BZOJ 1002 FJOI2007 轮状病毒 递推+高精度

    题目大意:轮状病毒基定义如图.求有多少n轮状病毒 这个递推实在是不会--所以我选择了打表找规律 首先执行下面程序 #include<cstdio> #include<cstring& ...

  6. ubuntu 12.10 笔记

    笔记 more ec_unitouch.log |grep Thread-4 筛选日志 打开命令行终端 ctrl + alt + t     查看版本号 : sudo lsb_release -a t ...

  7. 最新精品 强势来袭 XP,32/64位Win7,32/64位Win10系统【电脑城版】

    随着Windows 10Build 10074 Insider Preview版发布,有理由相信,Win10离最终RTM阶段已经不远了.看来稍早前传闻的合作伙伴透露微软将在7月底正式发布Win10的消 ...

  8. HDU 2473 Junk-Mail Filter(并查集的删除操作)

    题目地址:pid=2473">HDU 2473 这题曾经碰到过,没做出来. .如今又做了做,还是没做出来. ... 这题涉及到并查集的删除操作.想到了设一个虚节点,可是我把虚节点设为了 ...

  9. UIWebView使用中的内存相关问题

    本文转载至: http://blog.csdn.net/musou_ldns/article/details/7675589   applicationios5webkit测试cacheios 在iO ...

  10. 使用Retrofit发送POST请求提交JSON数据

    Retrofit官网:https://square.github.io/retrofit/ 示例如下 HttpService.java import okhttp3.RequestBody; impo ...