For specific algorithm principles, refer
PS layer hybrid algorithm 3 (filter color, overlay, soft light, strong light)
// 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_marshded
// Main Function
# Include "ps_algorithm.h"
Void screen (MAT & src1, mat & src2, mat & DST );
Void add_color (MAT & src1, mat & src2, mat & DST );
Void soft_lighten (MAT & src1, mat & src2, mat & DST );
Void strong_lighten (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.convertory (image_down, cv_32fc3 );
Image_up = image_up/255;
Image_down = image_down/255;
Mat image_mix (image_up );
// Screen (image_up, image_down, image_mix );
// Add_color (image_up, image_down, image_mix );
// Soft_lighten (image_up, image_down, image_mix );
// Strong_lighten (image_up, image_down, image_mix );
Namedwindow ("IMG", cv_window_autosize );
Imshow ("IMG", image_mix );
Waitkey ();
Cvdestroywindow ("IMG ");
Cout <"All is well." <Endl;
Return 0;
}
// Screen
Void screen (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] = 1-
(1-src1.at <vec3f> (index_row, index_col) [index_c]) *
(1-src2.at <vec3f> (index_row, index_col) [index_c]);
}
}
}
// Add color
Void add_color (MAT & src1, mat & src2, mat & DST)
{
Float a = 0;
Float B = 0;
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 ++)
{
A = src1.at <vec3f> (index_row, index_col) [index_c];
B = src2.at <vec3f> (index_row, index_col) [index_c];
If (B> 0.5)
{
DST. at <vec3f> (index_row, index_col) [index_c] = 2 * a * B;
}
Else
{
DST. at <vec3f> (index_row, index_col) [index_c] = 1-2 * (1-A) * (1-B );
}
}
}
}
}
// Soft lighten
Void soft_lighten (MAT & src1, mat & src2, mat & DST)
{
Float a = 0;
Float B = 0;
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 ++)
{
A = src1.at <vec3f> (index_row, index_col) [index_c];
B = src2.at <vec3f> (index_row, index_col) [index_c];
If (A <= 0.5)
{
DST. at <vec3f> (index_row, index_col) [index_c] = (2 * A-1) * (B-B * B) + B;
}
Else
{
DST. at <vec3f> (index_row, index_col) [index_c] = (2 * A-1) * (SQRT (B)-B) + B;
}
}
}
}
}
// Strong lighten
Void strong_lighten (MAT & src1, mat & src2, mat & DST)
{
Float a = 0;
Float B = 0;
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 ++)
{
A = src1.at <vec3f> (index_row, index_col) [index_c];
B = src2.at <vec3f> (index_row, index_col) [index_c];
If (A <= 0.5)
{
DST. at <vec3f> (index_row, index_col) [index_c] = 2 * a * B;
}
Else
{
DST. at <vec3f> (index_row, index_col) [index_c] = 1-2 * (1-A) * (1-B );
}
}
}
}
}