In this section, we will have a look at the various arithmetic operations that can be performed on images. Images are represented as matrices in OpenCV. So, arithmetic operations on images are similar to the arithmetic operations on matrices. Images must be of the same size for you to perform arithmetic operations on the images, and these operations are performed on individual pixels.
Note
We know that the subtraction operation is not commutative. So, cv2.subtract(img1,img2)
and cv2.(img2,img1)
will yield different results, whereas cv2.add(img1,img2)
and cv2.add(img2,img1)
will yield the same result as the addition operation is commutative. Both the images have to be of same size and type, as explained before.
Check out the following code:
import cv2 img1 = cv2.imread('/home/pi/book/test_set/4.2...