Arithmetic operations on images
We know that images are nothing but NumPy ndarrays and we can perform arithmetic operations on images just as we can perform them on ndarrays. If we know how to apply numerical or arithmetic operations to matrices, then we should not have any trouble doing the same when the operands for those operations are images. Images must be of the same size and must have the same number of channels for us to perform arithmetic operations on them, and these operations are performed on individual pixels. There are many arithmetic operations, such as addition and subtraction. The first is the addition operation. We can add two images by using either the NumPy Addition
or the add()
function in OpenCV, as follows:
import cv2 img1 = cv2.imread('/home/pi/book/dataset/4.2.03.tiff', 1) img2 = cv2.imread('/home/pi/book/dataset/4.2.05.tiff', 1) cv2.imshow('NumPy Addition', img1 + img2 ) cv2.imshow('OpenCV Addition', cv2.add(img1...