OpenCV——PS滤镜,渐变映射

时间:2024-11-10 09:36:20
// 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" using namespace std;
using namespace cv; void Show_Image(Mat&, const string &); #endif // PS_ALGORITHM_H_INCLUDED /*
This program will generate
"Shade" effect. */ #include "PS_Algorithm.h"
#include <time.h> using namespace std;
using namespace cv; int main(void)
{
string Img_name("4.jpg");
Mat Image_in;
Image_in=imread(Img_name);
Show_Image(Image_in, Img_name); Mat Image_out(Image_in.size(), CV_32FC3);
Image_in.convertTo(Image_out, CV_32FC3); Mat Image_2(Image_in.size(), CV_32FC3);
Image_in.convertTo(Image_2, CV_32FC3); Mat Map(Image_in.size(), CV_32FC3);
Mat temp;
float val; // build the mapping table
/*
for (int i=0; i<Image_2.rows; i++)
{
temp=Map.row(i);
val=(float)(i)/(float)Image_2.rows;
temp.setTo(Scalar(val,val,val));
}
*/ // build the mapping talbe
for (int i=0; i<Image_2.cols; i++)
{
temp=Map.col(i);
val=1-std::abs((float)(i)/((float)Image_2.cols/2)-1);
temp.setTo(Scalar(val,val,val));
} Show_Image(Map, "Map"); cv::multiply(Image_2, Map, Image_out); Image_out=Image_out/255.0; Show_Image(Image_out, "out"); imwrite("out.jpg", Image_out*255); waitKey();
cout<<"All is well."<<endl; } #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滤镜,渐变映射

效果图

OpenCV——PS滤镜,渐变映射