Detailed algorithm principles can be
PS Layer Blending algorithm two (linear burn, linear dodge, lighten, darken)
Ps_algorithm.h
#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;
#endif//ps_algorithm_h_included
Main function
#include "ps_algorithm.h"
void Linear_ Burn (mat& src1, mat& src2, mat& DST);
void Linear_dodge (mat& src1, mat& src2, mat& DST);
Void Lighten (mat& src1, mat& src2, mat& DST);
void Darken (mat& src1, mat& src2, mat& DST);
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);
Linear_burn (Image_up, Image_down, Image_mix);
Linear_dodge (Image_up, Image_down, Image_mix);
Lighten (image_up, Image_down, Image_mix);
Darken (image_up, Image_down, Image_mix);
Namedwindow ("Img", cv_window_autosize);
Imshow ("Img", Image_mix);
Waitkey ();
Cvdestroywindow ("Img");
cout<< "All are well." <<endl;
return 0;
}
Linear Burn
void Linear_burn (mat& src1, mat& src2, mat& DST)
{
for (int index_row=0; index_row<src1.rows; index_row++)
{
for (int index_col=0; index_col<src1.cols; index_col++)
{
for (int index_c=0; index_c<3; index_c++)
dst.at<vec3f> (Index_row, Index_col) [Index_c]=max (
src1.at<vec3f> (Index_row, Index_col) [index_c]+
src2.at<vec3f> (Index_row, Index_col) [Index_c]-1, (float) 0.0);
}
}
}
//Linear Dodge
void Linear_dodge (mat& src1, mat& src2, mat& DST)
{
for (int index_row=0; index_row<src1.rows; index_row++)
{
for (int index_col=0; index_col<src1.cols; index_col++)
{
for (int index_c=0; index_c<3; index_c++)
dst.at<vec3f> (Index_row, Index_col) [Index_c]=min (
src1.at<vec3f> (Index_row, Index_col) [index_c]+
src2.at<vec3f> (Index_row, Index_col) [Index_c], (float) 1.0);
}
}
}
//Lighten
void Lighten (mat& src1, mat& src2, mat& DST)
{
for (int index_row=0; index_row<src1.rows; index_row++)
{
for (int index_col=0; index_col<src1.cols; index_col++)
{
for (int index_c=0; index_c<3; index_c++)
dst.at<vec3f> (Index_row, Index_col) [Index_c]=max (
src1.at<vec3f> (Index_row, Index_col) [Index_c],
src2.at<vec3f> (Index_row, Index_col) [Index_c]);
}
}
}
Darken
void Darken (mat& src1, mat& src2, mat& DST)
{
for (int index_row=0; index_row<src1.rows; index_row++)
{
for (int index_col=0; index_col<src1.cols; index_col++)
{
for (int index_c=0; index_c<3; index_c++)
Dst.at<vec3f> (Index_row, Index_col) [Index_c]=min (
Src1.at<vec3f> (Index_row, Index_col) [Index_c],
Src2.at<vec3f> (Index_row, Index_col) [Index_c]);
}
}
Opencv--ps layer Blending algorithm (ii)