OpenCV——PS滤镜 漩涡 vertex
// 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;
int N=70;
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;
theta=atan(y0/(x0+0.00001));
if(x0<0) theta=theta+pi;
radius=sqrt(Dis);
theta=theta+radius/N;
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滤镜 漩涡 vertex的更多相关文章
- 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 ...
- PS 滤镜——漩涡 vortex
%%% Vortex %%% 漩涡效果 clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS A ...
- OpenCV——PS滤镜,渐变映射
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...
- OpenCV——PS滤镜,毛玻璃特效
程序完成 "毛玻璃" 特效, 不过边缘没有处理,使得最终的图像有黑边. 不过,有了黑边,感觉效果也不错,所以这个bug 没有管. #ifndef PS_ALGORITHM_H_IN ...
- 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 滤镜算法之平面坐标到极坐标的变换
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...
- OpenCV——PS滤镜之 波浪效果 wave
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...
随机推荐
- linux链接外网手动设置
/etc/sysconfig/network-scripts/ifcfg-eth0 设置IP网关等参数 DEVICE=eth0HWADDR=00:0C:29:C5:43:34TYPE=Etherne ...
- Oracle 修改带数据的字段类型
http://www.cnblogs.com/LDaqiang/articles/1157998.html由于需求变动,现要将一个类型NUMBER(8,2)的字段类型改为 char.大体思路如下: ...
- No bean named 'cxf' is defined
1.错误描写叙述 严重:Exception starting filter CXFServlet org.springframework.beans.factory.NoSuchBea ...
- Struts2学习六----------默认Action
© 版权声明:本文为博主原创文章,转载请注明出处 默认Action - 当访问action不存在时,可通过指定默认action的方式避免出现错误代码页面 - 使用default-action-ref指 ...
- 在 Ubuntu16.04上安装并使用Docker
介绍 Docker是一个开放源代码软件项目,让应用程序布署在软件容器下的工作可以自动化进行,借此在Linux操作系统上,提供一个额外的软件抽象层,以及操作系统层虚拟化的自动管理机制[1].Docker ...
- Xenomai 3 migration
Xenomai 3 的rtdm驱动更像一般的Linux驱动,named device会在/dev/rtdm/xxx创建一个设备文件.而用户空间使用时,写得来也和Linux的一般char设备相似,ope ...
- c# .net 我的Application_Error 全局异常抓取处理
protected void Application_Error(object sender, EventArgs e) { //在出现未处理的错误时运行的代码 ...
- 移除WordPress文章图片的宽度和高度属性
通过WordPress自身的媒体上传功能插入到文章的图片,都会默认添加了高度和宽度属性: <img title="使用 Chrome Workspace 进行网站调试 | 倡萌的自留地 ...
- Ubuntu/CentOS下编译Nginx最基本参数
Ubuntu/CentOS下编译Nginx安装基本参数,做个记录: groupadd www useradd -g www www ./configure --user=www --group=www ...
- python 基础 7.0 import 导入
一. python 常用内置模块的使用(datetime,logging,os,command) 在日常的开发工作中,我们要写很多的python 代码,如果都写在一个文件中,会导致代码特别 ...