// 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的更多相关文章

  1. PS 滤镜— —Twirl Filter

    clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); I=imread ...

  2. Opencv— — kaleidoscope Filter

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

  3. Opencv— — Circle Filter

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

  4. Opencv— — Pinch Filter

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

  5. PhotoShop 图像处理 算法 汇总

    不定期更新 ...... 直接点标题即可链接到原文. OpenCV 版:OpenCV 图像处理 图层混合算法: PS图层混合算法之一(不透明度,正片叠底,颜色加深,颜色减淡)PS图层混合算法之二(线性 ...

  6. 【Python】PIL模块

    Python自建库,在爬虫等基础应用中更加简单好记,做整理以备自查. 目录 Image模块 open类.Save类.format类.Mode类.convert类.Size类.Info类.new类.Co ...

  7. django 操作数据库--orm(object relation mapping)---models

    思想 django为使用一种新的方式,即:关系对象映射(Object Relational Mapping,简称ORM). PHP:activerecord Java:Hibernate C#:Ent ...

  8. 解析opencv中Box Filter的实现并提出进一步加速的方案(源码共享)。

    说明:本文所有算法的涉及到的优化均指在PC上进行的,对于其他构架是否合适未知,请自行试验. Box Filter,最经典的一种领域操作,在无数的场合中都有着广泛的应用,作为一个很基础的函数,其性能的好 ...

  9. 卡尔曼滤波—Simple Kalman Filter for 2D tracking with OpenCV

    之前有关卡尔曼滤波的例子都比较简单,只能用于简单的理解卡尔曼滤波的基本步骤.现在让我们来看看卡尔曼滤波在实际中到底能做些什么吧.这里有一个使用卡尔曼滤波在窗口内跟踪鼠标移动的例子,原作者主页:http ...

随机推荐

  1. 最新最全的 Android 开源项目合集

    原文链接:https://github.com/opendigg/awesome-github-android-ui 在 Github 上做了一个很新的 Android 开发相关开源项目汇总,涉及到 ...

  2. php 的$_POST 和$_REQUEST的区别

    发现$_POST 没数据,而$_REQUEST 有数据 ----------------------------------------- https://stackoverflow.com/ques ...

  3. Leet Code OJ 338. Counting Bits [Difficulty: Medium]

    题目: Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate ...

  4. vue2.0 + vux (二)Footer组件

    1.Footer组件 Footer.vue <!-- 底部 footer --> <template> <div> <tabbar> <!-- 综 ...

  5. Nginx 第三方模块的安装以及一致性哈希算法的使用

    Nginx 第三方模块的安装以及一致性哈希算法的使用 第三方模块安装方法总结: 以ngx_http_php_memcache_standard_balancer-master为例 1:解压 到 pat ...

  6. 常见Struts、Hibernate、Spring、J2EE、ibatis、Oracle等开发框架架构图及其简介

    各种系统架构图及其简介 转载请保留出处,不胜人生一场醉汇总. 以下文字和架构图均在本人相关系统设计和架构方案中有所应用. 原文出处:http://space.itpub.net/6517/viewsp ...

  7. HDMI各版本对比

    转:一文看懂从HDMI1.0到HDMI2.1的历代规格变化 hdmi HDMI详解 https://blog.csdn.net/xubin341719/article/details/7713450 ...

  8. 从头认识java-14.1 再次对照数组与容器

    这一章节我们再次深入的对照数组与容器. 数组与容器主要集中在三个方面:效率.类型.基础类型. 我们能够从三方面做出对照. 1.效率 这里的下来是指add和get 的速度 以下以add为例: packa ...

  9. Active Directory的LDAP协议与DN(Distinguished Name)详解

    前言 光copy几段代码的文章没什么意思,本章上最基础的代码,主要是为了从编程方面聊LDAP和DN,其它的后面聊,一步步慢慢来吧. Active Directory编程须知 1.域控服务器: Wind ...

  10. 横向卷轴(side-scrolling)地图的canvas实现

    标题有点小题大作了,实际上是实现一张看起来连续的运动背景图片. 效果如下:   // 实现原理: 图片1与图片2是两张首尾衔接的图片,图片1以一定速度移出canvas,图片2慢慢移进canvas,当图 ...