Opencv-PS layer hybrid algorithm (4)

Source: Internet
Author: User

For specific algorithm principles, refer

PS Layer Mixing algorithm 4 (light, dot light, linear light, solid color)

// 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 vivid_lighten (MAT & src1, mat & src2, mat & DST );
Void pin_lighten (MAT & src1, mat & src2, mat & DST );
Void linear_lighten (MAT & src1, mat & src2, mat & DST );
Void hard_mix (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 );

// Vivid_lighten (image_up, image_down, image_mix );
// Pin_lighten (image_up, image_down, image_mix );
// Linear_lighten (image_up, image_down, image_mix );
// Hard_mix (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;
}

// Vivid lighten
Void vivid_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] = 1-(1-B)/(2 * );
}
Else
{
DST. at <vec3f> (index_row, index_col) [index_c] = B/(2 * (1-A ));
}
}
}
}
}

// Pin lighten
Void pin_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 (B <= 2 * A-1)
{
DST. at <vec3f> (index_row, index_col) [index_c] = 2 * A-1;
}
Else if (B <= 2 *)
{
DST. at <vec3f> (index_row, index_col) [index_c] = B;
}
Else
{
DST. at <vec3f> (index_row, index_col) [index_c] = 2 *;
}
}
}
}
}

// Linear lighten
Void linear_lighten (MAT & src1, mat & src2, mat & DST)
{
DST = src2 + 2 * src1-1;
}

// Hard mix
Void hard_mix (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 <1-B)
{
DST. at <vec3f> (index_row, index_col) [index_c] = 0.0;
}
Else
{
DST. at <vec3f> (index_row, index_col) [index_c] = 1.0;
}
}
}
}
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.