//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 #include "ps_algorithm.h"#include <time.h>using namespace STD;using namespaceCv#define PI 3.1415926intMain () {stringImg_name ("4.jpg"); Mat Img; Img=imread (Img_name); Mat img_out (Img.size (), CV_8UC3);intWidth=img.cols;intHeight=img.rows;floatrnw=1.0;floatgnw=0.0;floatbnw=0.0;floatRne=1.0;floatGne=1.0;floatBne=0.0;floatrsw=0.0;floatgsw=0;floatbsw=1.0;floatRse=0.0;floatGse=1.0;floatBse=0.0;floatFX, FY;floatP, Q, R, G, B; for(inty=0; y for(intx=0; x<width; X + +) {fx= (float) (x)/width; Fy= (float) (y)/height; p = RNW + (RNE-RNW) * FX; Q = RSW + (RSE-RSW) * FX; R = (p + (q-p) * fy); r = Min (max (R,0.0f),1.0f); p = gnw + (GNE-GNW) * FX; Q = GSW + (GSE-GSW) * FX; g = (p + (q-p) * fy); g = min (Max (g,0.0f) ,1.0f); p = BNW + (BNE-BNW) * FX; Q = BSW + (BSE-BSW) * FX; b = (p + (q-p) * fy); b = min (max (b,0.0f),1.0f); Img_out.at<vec3b> (y, x) [0]=b*255.0; Img_out.at<vec3b> (y, x) [1]=g*255.0; Img_out.at<vec3b> (y, x) [2]=r*255.0; }} show_image (Img_out,"Out");cout<<" all are well"<<endl;//Imwrite ("Out.jpg", img_out);Waitkey ();}//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/46906849
Opencv--color Gradient