Arithmetic operations such as addition, subtraction, and bitwise operations (AND, OR, NOT, XOR) can be applied to input images. These operations can be useful for improving the properties of the input images. Image arithmetic is important for analyzing the properties of the input image. Driven images can optionally be used as an enhanced input image, and much more operations can be applied to the image to lighten, threshold, expand, etc.
Add an image:
We can add two images using the cv2.add () function. This directly adds image pixels to two images.
Syntax: cv2.add (img1, img2)
But adding pixels is not ideal. So we are using cv2.addweighted ()
. Remember that both images must be the same size and depth.
Syntax : cv2.addWeighted (img1, wt1, img2, wt2, gammaValue)
Parameters :
img1 : First Input Image array (Single-channel, 8-bit or floating-point)
wt1 : Weight of the first input image elements to be applied to the final image
img2 : Second Input Image array (Single-channel, 8-bit or floating-point)
wt2 : Weight of the second input image elements to be applied to the final image
gammaValue : Measurement of light
Images used as input:
Input image1:

Input image2:

Below is the code:
|
Output:

Image subtraction :
Like addition, we can subtract the pixel values in two images and combine them using cv2.subtract ()
. Images must be the same size and depth.
Syntax: cv2.subtract (src1, src2)
Images used as input:
Input image1:

Input image2:

Below is the code:
|
Output:
