OpenCV——PS滤镜算法之 Ellipsoid (凹陷)
// 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 e;
float a,b, a0, b0, a1,b1;
float alpha=1.0;
float K=pi/2;
a=width/2; b=height/2;
e=(float)width/(float)height;
Point2i Center(width/2, height/2);
float 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*e/(x0+0.0001));
if(x0<0) theta=theta+pi;
a0=x0/cos(theta);
b0=y0/sin(theta+0.0001);
if(a0>a || b0>b) continue;
a1=a*sin(a0/a*K);
b1=b*sin(b0/b*K);
a1=(a1-a0)*(alpha)+a0;
b1=(b1-b0)*(alpha)+b0;
new_x=a1*cos(theta);
new_y=b1*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];
}
}
}
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滤镜算法之 Ellipsoid (凹陷)的更多相关文章
- OpenCV——PS滤镜算法之 球面化 (凹陷效果)
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...
- OpenCV——PS滤镜算法之 Ellipsoid (凸出)
// 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滤镜算法之Spherize 球面化(凸出效果)
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...
- 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 滤镜算法原理——染色玻璃
%%%% 完成PS 中的染色玻璃滤镜特效 clc; clear all; close all; Image=imread('4.jpg'); Image=double(Image); Gray_Ima ...
- PS 滤镜算法原理 ——马赛克
% method : 利用邻域的随意一点取代当前邻域全部像素点 %%%% mosaic clc; clear all; addpath('E:\PhotoShop Algortihm\Image Pr ...
随机推荐
- laravel 查询构造器
//查询构造器public function query(){ $bool = DB::table('student')->insert([ ['name' => '王五', 'age' ...
- jQuery插件封装系列(一)—— 金额录入框
基于jQuery原型封装数值录入框,禁止录入.粘贴非数值字符 (function ($) { // 数值输入框 $.fn.numbox = function (options) { var type ...
- 接口自动化测试之HTTP协议详解
协议 简单理解,计算机与计算机之间的通讯语言就叫做协议,不同的计算机之间只有使用相同的协议才能通信.所以网络协议就是为计算机网络中进行数据交换而建立的规则,标准或约定的集合. OSI模型 1978年国 ...
- sugar与阿龙的互怼(第一季)
§ 第一季 回家风波 高考了,啦啦啦~ 快要高考了,显然sugar很伤心. 显然不是因为快要考试了sugar才伤心的. 那为什么??? 因为他们都回家了,但是sugar和他的小伙伴们都不回家!!! ...
- Redhat 5 无法安装elfutils-libelf-devel-0.137问题
http://whr25.blog.sohu.com/263584338.html 问题: RHEL5.5安装oracle11gR2的时候需要安装elfutils-libelf-devel-0.137 ...
- 怎样高速地安装Ubuntu SDK
我在先前的文章"Ubuntu SDK 安装"中已经具体地介绍了怎样安装Ubuntu SDK.可是非常多的开发人员可能在最后安装SDK所须要的chroots时候会失败.这里面的原因是SDK在安装chro ...
- MFC 小知识总结三
1 载入资源位图 1 获取程序实例 HINSTANCE m_hInst; m_hInst=AfxGetInstanceHandle(); //获取程 ...
- android_checkbox_dialog 设计 是不是要开起 默认不提示对话框
android_checkbox_dialog设计是不是开起默认不提示 package com.example.android_checkbox_dialog; import android.app. ...
- Flex事件机制学习-自定义事件实现类间通信 .
今天,学习Flex自定义事件,可以使两个类通信,定义一个Main类. public class Main extends Sprite { public function ...
- eclipse使用正则表达式查找文件内容
今天有个需求,查找工程中包含汉字的所有文件,随即想到利用eclipse的search功能配合正则表达式. 在eclipse中Ctrl+H,然后在Containing text中输入[\u4e00-\u ...