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 (&IMG1); Cvreleaseimage (&IMG2); Cvreleaseimage (&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"