//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 namespaceCvvoidShow_image (Mat&,Const string&);#endif //ps_algorithm_h_included /*generate the Circle transform*/#include "ps_algorithm.h"#include <time.h>using namespace STD;using namespaceCv#define PI 3.1415926floatTriangle (floatx);intMain () {stringImg_name ("4.jpg"); Mat Img; Img=imread (Img_name); Mat img_out (Img.size (), CV_8UC3);intWidth=img.cols;intHeight=img.rows;floatAngle = pi/4;floatangle2=pi/4;floatCentreX =0.5;floatCentrey =0.5;floatsides =Ten;floatIcentrex=width*centrex;floatIcentrey=height*centrey;floatradius= Max;floatdx,dy,new_x,new_y;floatP,q,x1,y1;floatC, R, Theta, Temp_theta, Radius_c; for(inty=0; y for(intx=0; x<width; X + +) {Dx=x-icentrex; Dy=y-icentrey; Theta=atan2(Dy, dx)-angle-angle2; R=sqrt(DY*DY+DX*DX); Temp_theta=theta/pi*sides*0.5; Theta=triangle (Temp_theta);if(RADIUS) {c=Cos(theta); radius_c=radius/c; R=radius_c * Triangle (R/radius_c); } Theta=theta+angle; New_x=r *Cos(theta) +icentrex; New_y=r *Sin(theta) +icentrey;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;//if (new_x<0) continue; //if (new_x>=width-1) continue; //if (new_y>=height-1) continue; //if (new_y<0) continue;X1= (int) new_x; Y1= (int) new_y; p=new_x-x1; Q=new_y-y1; for(intk=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 are well"<<endl;//Imwrite ("Out.jpg", img_out);Waitkey ();}floatTriangle (floatx) {floatTemp_r=Fmod(X,1.0);if(temp_r<0.5) {return 2*temp_r; }Else{return 2*(1-TEMP_R); }}//define the show image#include "ps_algorithm.h"#include <iostream>#include <string>using namespace STD;using namespaceCvvoidShow_image (mat& Image,Const string& str) {Namedwindow (Str.c_str (), cv_window_autosize); Imshow (Str.c_str (), Image);}
Image effects can be referenced by:
http://blog.csdn.net/matrix_space/article/details/46789783
Opencv--kaleidoscope Filter