1. Addition operation of image
The addition operation of a graph is actually the addition operation of a matrix, so the size of two graphs must be the same to add. The specific api is add (A, B)
2. Subtraction of image
The subtraction api is subtrack (A, B). Subtraction is positional. A-B and B-A are completely different results, so the order should be determined.
3. Multiplication and division of images
The multiplication api is multiply (A, B), and the division api is divide (A, B). Image multiplication and division are similar to addition and subtraction, which can make the picture brighter or darker, and the degree of multiplication and division is greater.
import cv2 import numpy as np # 导入一张图片 img=cv2.imread('20220627220106.jpg') # 查看图片尺寸 print(img.shape) # 创建另外一张图 img1=np.ones((787,1205,3),np.uint8)*100 # 显示原图 cv2.imshow('orig',img) # 图片相加 result=cv2.add(img,img1) # 显示相加后的图片 cv2.imshow('result',result) # 图像相减 img3=cv2.subtract(result,img1) cv2.imshow('orig_1',img3) # 图像相乘 img4=cv2.multiply(img,img1) cv2.imshow('img4',img4) # 图像相除 img5=cv2.divide(img,img1) cv2.imshow('img5',img5) cv2.waitKey(0)