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
#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 A,B;
A=7;
B=2.5;
Point Center(width/2, height/2);
float r0,r1,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;
theta=atan(y0/(x0+0.00001));
if(x0<0) theta=theta+pi;
r0=sqrt(x0*x0+y0*y0);
r1=r0+A*width*0.01*sin(B*0.1*r0);
new_x=r1*cos(theta);
new_y=r1*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滤镜 水波效果的更多相关文章
- PS 滤镜— —水波效果
clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); I=imread ...
- PS 滤镜——水波 water wave
%%%% Water wave %%%% 制作水波效果 clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Process ...
- Python: PS 滤镜--水波特效
本文用 Python 实现 PS 滤镜中的 水波特效 import numpy as np from skimage import img_as_float import matplotlib.pyp ...
- 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——PS滤镜之 波浪效果 wave
// 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 < ...
- Python: PS 滤镜--万花筒效果
本文用 Python 实现 PS 的一种滤镜效果,称为万花筒.也是对图像做各种扭曲变换,最后图像呈现的效果就像从万花筒中看到的一样: 图像的效果可以参考之前的博客: http://blog.csdn. ...
随机推荐
- iOS -- 字符串(NSString *)转uint8_t的两种方法
// 第一种 NSString *connID = ((Collector *)weakSelf.globalMutableArray[i]).orignalConnID; ] intValue]; ...
- Direct2D教程(九)渲染位图
概述 这篇的标题更确切的说应该叫位图画刷,这样才好和前几篇对应起来.在Direct2D中,位图的渲染也是通过画刷来实现的. Direct2D中并没有直接操作位图的接口,而是借助WIC(Windows ...
- TensorFlow 之 高层封装slim,tflearn,keras
tensorflow资源整合 使用原生态TensorFlow API来实现各种不同的神经网络结构.虽然原生态的TensorFlow API可以很灵活的支持不同的神经网络结构,但是其代码相对比较冗长,写 ...
- 第五讲_图像识别之图像检测Image Detection
第五讲_图像识别之图像检测Image Detection 目录 物体检测 ILSVRC竞赛200类(每个图片多个标签):输出类别+Bounding Box(x,y,w,h) PASCAL VOC 20 ...
- linux下脚本监控网络流量
linux下脚本监控网络流量 学习了:https://blog.csdn.net/chenghuikai/article/details/48437479 学习了:http://www.jb51.ne ...
- C#遇见的函数
1.类Stopwatch 提供一组方法和属性,可用于准确地测量运行时间. 命名空间: System.Diagnostics Stopwatch timePerParse = Stopwatc ...
- require.js使用
无可奈何,二开项目用了require.js! 一道槛是挨不过去了 require官网: http://requirejs.org/ require.js cdn: <script src=&qu ...
- POJ 3978(求素数)
知识点: 1.求素数的test,从2~sqrt(n): 2.假设数据非常多,能够用素数表记录,然后sum=prime[m]-prime[n]求得! ! !! !!! !! ...
- 关于 AlphaGo 论文的阅读笔记
这是Deepmind 公司在2016年1月28日Nature 杂志发表论文 <Mastering the game of Go with deep neural networks and tre ...
- 数据结构与算法——AVL树类的C++实现
关于AVL树的简单介绍能够參考:数据结构与算法--AVL树简单介绍 关于二叉搜索树(也称为二叉查找树)能够參考:数据结构与算法--二叉查找树类的C++实现 AVL-tree是一个"加上了额外 ...