[Open CV Basics] Alpha Fusion of the two images,

Source: Internet
Author: User

[Open CV Basics] Alpha Fusion of the two images,

In the image operation of Open CV, we can use the cvAddWeighted function to achieve the fusion of the 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 image
Alpha First image parameter during Fusion
Src2 Type 2 Image
Beta The second image parameter during Fusion
Gamma Constant, usually depends on the average value and maximum value to be adjusted to the pixel.
Dst Merged image

The function of this function is weighted fusion image. The pixels of each pixel are calculated based on the pixel weights of the corresponding pixels of the two source images. The fusion formula is as follows:

Dst = alpha * src1 + beta * src2 + gamma
When alpha is a, beta is 1-a, and gamma is 0, where a> = 0 and a <= 1, the fusion equation is called the standard fusion equation.

The following is an example:

# Include "cv. h "# include" highgui. h "int main () {// name of the two images to be merged char * imgStr1 =" faceScene.jpg "; char * imgStr2 =" fruits.jpg "; // open two images: IplImage * img1 = cvLoadImage (imgStr1); IplImage * img2 = cvLoadImage (imgStr2 ); // set parameters alpha, beta, and gamma to a, 1-a, and 0, respectively. This is the standard Alpha Fusion equation float alpha = 0.3; float beta = 0.7; float gamma = 0; // create an image to receive the merged image IplImage * dst = cvCreateImage (cvSize (img1-> width, img1-> height), img1-> depth, 3); // use cvAddWeighted to execute Alpha Fusion cvAddWeighted (img1, alpha, img2, beta, gamma, dst); // output three images to view the 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 (& img1); cvReleaseImage (& img2); cvReleaseImage (& dst); cvDestroyWindow (s1 ); cvDestroyWindow (s2); cvDestroyWindow (s3 );}

Image to be merged 1:

Image to be merged 2:

Merged images:

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.