Besides the simple addition of two images, you can also use the weighted addition function to consider a weight for each of the two images that are being added. Think of it as setting an opacity level for each of the participants in an add operation. To perform a weighted addition, you can use the addWeighted function:
double alpha = 1.0; // First image weight double beta = 0.30; // Second image weight double gamma = 0.0; // Added to the sum addWeighted(image, alpha, overlay, beta, gamma, result);
If executed on the sample pictures from the previous section with the add example, the result would be similar to the following:
Notice the transparent text that is similar to the watermark usually applied by photo-editing applications. Notice the comments in the code regarding the alpha, beta, and gamma values? Obviously, providing a beta value of 1.0 would have made this example exactly the same as a regular add function with no transparency for the overlay text.