Opencv— — Twirl Filter
// 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
/*
generate the twirl effect
*/
#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 angle = pi/3;
float centreX = 0.5;
float centreY = 0.5;
float radius = 0;
if (radius==0) radius=std::min(width, height)/2;
float icentreX=width*centreX;
float icentreY=height*centreY;
float radius2=radius*radius;
float dx,dy,new_x,new_y;
float p,q,x1,y1;
float distance, distance2;
float a;
for (int y=0; y<height; y++)
{
for (int x=0; x<width; x++)
{
dx=x-icentreX;
dy=y-icentreY;
distance2=dx*dx+dy*dy;
if (distance2>radius2)
{
new_x=x;
new_y=y;
}
else
{
distance=sqrt(distance2);
a = std::atan2(dy, dx) + angle * (radius-distance) / radius;
new_x = icentreX + distance*cos(a);
new_y = icentreY + distance*sin(a);
}
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];
}
}
}
Show_Image(Img_out, "out");
cout<<"All is well"<<endl;
// 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);
}
图像效果可以参考:
http://blog.csdn.net/matrix_space/article/details/46789311
Opencv— — Twirl Filter的更多相关文章
- PS 滤镜— —Twirl Filter
clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); I=imread ...
- Opencv— — kaleidoscope Filter
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...
- Opencv— — Circle Filter
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...
- Opencv— — Pinch Filter
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...
- PhotoShop 图像处理 算法 汇总
不定期更新 ...... 直接点标题即可链接到原文. OpenCV 版:OpenCV 图像处理 图层混合算法: PS图层混合算法之一(不透明度,正片叠底,颜色加深,颜色减淡)PS图层混合算法之二(线性 ...
- 【Python】PIL模块
Python自建库,在爬虫等基础应用中更加简单好记,做整理以备自查. 目录 Image模块 open类.Save类.format类.Mode类.convert类.Size类.Info类.new类.Co ...
- django 操作数据库--orm(object relation mapping)---models
思想 django为使用一种新的方式,即:关系对象映射(Object Relational Mapping,简称ORM). PHP:activerecord Java:Hibernate C#:Ent ...
- 解析opencv中Box Filter的实现并提出进一步加速的方案(源码共享)。
说明:本文所有算法的涉及到的优化均指在PC上进行的,对于其他构架是否合适未知,请自行试验. Box Filter,最经典的一种领域操作,在无数的场合中都有着广泛的应用,作为一个很基础的函数,其性能的好 ...
- 卡尔曼滤波—Simple Kalman Filter for 2D tracking with OpenCV
之前有关卡尔曼滤波的例子都比较简单,只能用于简单的理解卡尔曼滤波的基本步骤.现在让我们来看看卡尔曼滤波在实际中到底能做些什么吧.这里有一个使用卡尔曼滤波在窗口内跟踪鼠标移动的例子,原作者主页:http ...
随机推荐
- iOS -- xxxViewController进行pop时直接crash进main.m,EXC_BAD_ACCESS(code=1,address=0x20)
今天在调试程序时,遇到了奇怪的错误.我从主页跳进(push)一个ViewController时一切正常,但是返回主页(pop)时却crash了,直接跳进了main.m(EXC_BAD_ACCESS(c ...
- mac异常删除管理员账户恢复操作
重新启动电脑,同时按下command+s键进入命令行方式 待系统加载完成后顺序输入以下命令: /sbin/mount -uaw rm var/db/.applesetupdone reboot 待系统 ...
- NHibernate剖析:Mapping篇之Mapping-By-Code(1):概览
ModelMapper概述 NHibernate3.2版本号集成Mapping-By-Code(代码映射),其设计思想来源于ConfORM.代码总体构思基于"Loquacious" ...
- Flash中如何使用滤镜
使用滤镜 应用或删除滤镜 复制和粘贴滤镜 为对象应用预设滤镜 启用或禁用应用于对象的滤镜 启用或禁用应用于对象的所有滤镜 创建预设滤镜库 对象每添加一个新的滤镜,在属性检查器中,就会将其添加到该对象所 ...
- python(37)- 软件开发规范
软件开发规范 一.为什么要设计好目录结构? 1.可读性高: 不熟悉这个项目的代码的人,一眼就能看懂目录结构,知道程序启动脚本是哪个,测试目录在哪儿,配置文件在哪儿等等.从而非常快速的了解这个项目. 2 ...
- Python中cv2库和matplotlib库色彩空间排布不一致
今天在python中读如图片时发现以下问题: 1.在from matplotlib import pyplot as plt之后,再import cv2 cv2.imshow()不能正常使用,还不知道 ...
- iOS应用数据存储的经常使用方式
ios程序中数据数据存储有下列5种方式 XML属性列表(plist)归档 Preference(偏好设置) NSKeyedArchiver归档(NSCoding) SQLite3 Core Data ...
- Linux下查看系统CPU个数、核心数、线程数
1.查看物理CPU个数 (env) root@vmware01:~# grep 'physical id' /proc/cpuinfo physical physical physical physi ...
- POJ 3469(Dual Core CPU-最小割)[Template:网络流dinic V2]
Language: Default Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 19321 ...
- 使用kubernetes 官网工具kubeadm部署kubernetes(使用阿里云镜像)
系列目录 kubernetes简介 Kubernetes节点架构图: kubernetes组件架构图: 准备基础环境 我们将使用kubeadm部署3个节点的 Kubernetes Cluster,整体 ...