Alpha Fusion of two images "Open CV Basics"

Source: Internet
Author: User

In the image operation of the open CV, we can use the cvaddweighted function to achieve the fusion of two images, the complete signature of the function is:

void cvAddWeighted(     const CvArr* src1,      double alpha,     const CvArr* src2,      double beta,     double gamma,      CvArr* dst  );
Parameters meaning
Src1 First picture
Alpha The first picture parameter when merging
Src2 The second kind of picture
Beta The second picture parameter when merging
Gamma Constant items, often depending on the average and maximum values to which the pixels are to be adjusted
Dst Image after merging

The function is weighted fusion image, the pixel of each pixel is the pixel weighting of the corresponding pixel points of the two provenance images, the fusion formula is as follows:

DST = alpha*src1 + beta*src2 + Gamma
When Alpha is a,beta to 1-a,gamma as 0, wherein, a>=0 and a<=1, the fusion equation is called the standard fusion equation.

Here's an example:

#include "cv.h"#include "highgui.h"intMain () {//Two picture names to be fused    Char* IMGSTR1 ="Facescene.jpg";Char* IMGSTR2 ="Fruits.jpg";//Open two photosiplimage* img1 = Cvloadimage (IMGSTR1); iplimage* Img2 = Cvloadimage (IMGSTR2);//Set alpha, beta, gamma parameters    //Set the values of the three to a,1-a and 0, which are standard alpha fusion equations    floatAlpha =0.3;floatBeta =0.7;floatGamma =0;//Create a picture to receive the fused imageiplimage* DST = cvcreateimage (Cvsize (Img1->width, Img1->height), Img1->depth,3);//Use cvaddweighted to perform alpha fusionCvaddweighted (IMG1, alpha, IMG2, beta, Gamma, DST);//Output three pictures view effect    Char* S1 ="IMG1", *s2 ="Img2", *S3 ="DST"; Cvnamedwindow (S1); Cvnamedwindow (S2);    Cvnamedwindow (S3); Cvshowimage (S1, IMG1); Cvshowimage (S2, IMG2);    Cvshowimage (S3, DST); Cvwaitkey (0);    Cvreleaseimage (&AMP;IMG1);    Cvreleaseimage (&AMP;IMG2);    Cvreleaseimage (&AMP;DST); Cvdestroywindow (S1); Cvdestroywindow (S2); Cvdestroywindow (S3);}

Image to be fused 1:

Image to be fused 2:

Image of Successful fusion:

Alpha Fusion of two images "Open CV Basics"

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.