// 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 R;
float e;
float a,b;
float alpha=0.75;
float K=pi/2; a=height/2.0; b=width/2.0;
e=(float)width/(float)height;
R=std::min(a,b); Point Center(width/2, height/2); float radius,Dis,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;
Dis=x0*x0+y0*y0;
if(Dis<R*R)
{
theta=atan(y0/(x0+0.00001));
if(x0<0) theta=theta+pi;
radius=asin(sqrt(Dis)/R)*R/K;
radius=(sqrt(Dis)-radius)*(1-alpha)+radius;
new_x=radius*cos(theta);
new_y=radius*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];
} } }
} Img_out=Img_out;
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滤镜算法之Spherize 球面化(凸出效果)的更多相关文章

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

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

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

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

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

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

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

    // 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 滤镜——(扭曲)球面化 Spherize

    %%%% Spherize clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorit ...

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

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

随机推荐

  1. Android · 广告走灯

    layout <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:and ...

  2. arcgis水文分析

    前言 1.在开始之前首先需要注意几点: 1.arcgis 需要 python2.7 的支持,并有必要的模块库,请一定注意避免与其他软件冲突,例如tecplot 2009 需要python2.5的支持, ...

  3. Paxos算法学习

    早在1990年,Leslie Lamport(即 LaTeX 中的"La",微软研究院科学家,获得2013年图灵奖)向ACM Transactions on Computer Sy ...

  4. C#中方法中 ref 和 out的使用

    案例1: static void Main() { , , , }; int numLargerThan10,numLargerThan100,numLargerThan1000 ; Proc(ary ...

  5. 深入Asyncio(九)异步生成器

    Async Generators:yield inside async def functions 如果在async def中使用yield会发生什么,答案就是生成一个异步生成器函数,如果有生成器.协 ...

  6. Docker入门系列1:简介

    可以实现快速部署. 比如一台 16 核 32G 内存的虚拟机上,需要跑 500+ 个用户的应用(每个应用的功能可以认为是一个网站 + 一系列的 RESTful API),有两个事情很重要: 资源隔离: ...

  7. python 基础 4.1 函数的参数

    #/usr/bin/python #coding=utf-8 #@Time   :2017/10/24 9:09 #@Auther :liuzhenchuan #@File   :函数的参数.py # ...

  8. JS基础知识再整理..........不断更新中

    1.JS的五种基本数据类型:字符串.数值.布尔.null.underfined. 2.在JS中,字符串.数值.布尔三种数据类型,有其属性和方法: 3.字符串的三种常用方法[.indexof()..su ...

  9. 用Darwin和live555实现的直播框架

    我们在开发视频直播或者监控类项目的时候,如场馆监控.学校监控.车载监控等等,往往首先希望的是形成一个项目的雏形,然后再在这个框架的基础上进行不断的完善和扩展工作,那么我们今天要给大家介绍的就是,如何形 ...

  10. 20179209《Linux内核原理与分析》第一周作业

    如何揭开Linux操作系统的最大面纱 个人认为,真正理解一个操作系统最根本的就是理解其文件系统结构. 自windows图形界面诞生,国内大多数用户都选择了windows操作系统,很多人觉得window ...