具体的算法原理可以参考:
PS图层混合算法之六(差值,溶解, 排除)
// PS_Algorithm.h
#ifndef PS_ALGORITHM_H_INCLUDED
#define PS_ALGORITHM_H_INCLUDED
#include#include
#include "cv.h"
#include "highgui.h"
#include "cxmat.hpp"
#include "cxcore.hpp"
using namespace std;using namespace cv;
#endif // PS_ALGORITHM_H_INCLUDED
// main function
#include "PS_Algorithm.h"
void Difference(Mat& src1, Mat& src2, Mat& dst);
void Exclusion(Mat& src1, Mat& src2, Mat& dst);
void Dissolve(Mat& src1, Mat& src2, Mat& dst, double alpha);
int main(void)
{
Mat Origin_Image1;
Mat Origin_Image2;
Origin_Image1=imread("2.jpg");
Origin_Image2=imread("3.jpg");
Mat Image_up(Origin_Image1.size(),CV_32FC3);
Mat Image_down(Origin_Image2.size(), CV_32FC3);
Origin_Image1.convertTo(Image_up,CV_32FC3);
Origin_Image2.convertTo(Image_down,CV_32FC3);
Image_up=Image_up/255;
Image_down=Image_down/255;
Mat Image_mix(Image_up);
//Difference(Image_up, Image_down, Image_mix);
//Exclusion(Image_up, Image_down, Image_mix);
//Dissolve(Image_up, Image_down, Image_mix, 0.75);
namedWindow("Img", CV_WINDOW_AUTOSIZE);
imshow("Img",Image_mix);
waitKey();
cvDestroyWindow("Img");
cout<<"All is well."<
}
// Difference
void Difference(Mat& src1, Mat& src2, Mat& dst)
{
float a=0;
float b=0;
for(int index_row=0; index_row
{
for(int index_col=0; index_col
{
for(int index_c=0; index_c<3; index_c++)
{
a=src1.at
b=src2.at
dst.at
}
}
}
}
// Exclusion
void Exclusion(Mat& src1, Mat& src2, Mat& dst)
{
float a=0;
float b=0;
for(int index_row=0; index_row
{
for(int index_col=0; index_col
{
for(int index_c=0; index_c<3; index_c++)
{
a=src1.at
b=src2.at
dst.at
}
}
}
}
// Dissolve
void Dissolve(Mat& src1, Mat& src2, Mat& dst, double alpha)
{
dst=src1;
Mat Rand_mat(src1.size(), CV_32FC1);
cv::randu(Rand_mat, 0,1);
float a=0;
float b=0;
for(int index_row=0; index_row
{
for(int index_col=0; index_col
{
b=Rand_mat.at
if(b
{
for(int index_c=0; index_c<3; index_c++)
{
a=src2.at
dst.at
}
}
}
}
}