The addition operation

The add function and the + operator can be used to add the elements of two matrices, or a matrix and a scalar, as seen in the following examples:

Mat image = imread("Test.png"); 
Mat overlay = imread("Overlay.png"); 
Mat result; 
add(image, overlay, result); 

You can replace the last line in the preceding code with the following:

result = image + overlay; 

The following image demonstrates the resulting image of an add operation of two images:

In case, you want to add a single scalar value to all elements of a Mat object, you can simply use something similar to the following:

result = image + 80; 

If the preceding code is executed on a grayscale image, the result will be brighter than the source image. Note that if the image has three channels, you must use a three-item vector instead of a single value. For instance, to be able to make an RGB image brighter, you can use the following:

result = image + Vec3b(80, 80, 80); 

Here's an image depicting the brighter result image, when the preceding code is executed on it:

In the preceding example codes, simply increase the added value to get an even brighter image.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.144.108