The multiplication and division operations

Similar to addition and subtraction, you can also multiply all elements of a Mat object with all elements of another Mat object. The same can be done with the division operation. Again, both operations can be performed with a matrix and a scalar. Multiplication can be done using OpenCV's multiply function (similar to the Mat::mul function), while division can be performed using the divide function.

Here are some examples:

double scale = 1.25; 
multiply(imageA, imageB, result1, scale); 
divide(imageA, imageB, result2, scale); 

scale in the preceding code is an additional parameter that can be supplied to the multiply and divide functions to scale all of the elements in the result Mat object. You can also perform multiplication or division with a scalar, as seen in the following examples:

resultBrighter = image * 5; 
resultDarker = image / 5; 

Obviously, the preceding code will produce two images, one that is five times brighter and one that is five times darker than the original image. The important thing to note here is that, unlike addition and subtraction, the resulting image will not be homogeneously brighter or darker, and you'll notice that brighter areas become much brighter and vice versa. The reason for this is obviously the effect of multiplication and division operations, in which the value of brighter pixels grows or drops much faster than smaller values after the operation. It's interesting to note that this same technique is used in most photo-editing applications to brighten or darken the bright areas of an 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