代码
解释都在注释里啦
import cv2 as cv
#数值计算:要求两张图片shape一样
def value(p1,p2):
img1=cv.add(p1,p2)#加
img2=cv.subtract(p1,p2)#减
img3=cv.multiply(p1,p2)#乘
img4=cv.divide(p1,p2)#除
cv.imshow("plus",img1)
cv.imshow("subtract",img2)
cv.imshow("multiply",img3)
cv.imshow("divide",img4)
#逻辑运算
def logic(p1,p2):
img1=cv.bitwise_and(p1,p2)#与
img2=cv.bitwise_or(p1,p2)#或
img3=cv.bitwise_not(p1,p2)#非
img4=cv.bitwise_xor(p1,p2)#异或
cv.imshow("and", img1)
cv.imshow("or", img2)
cv.imshow("not", img3)
cv.imshow("xor", img4)
src1 = cv.imread("Linux.jpg")
src2 = cv.imread("Window.jpg")
cv.imshow("Before1", src1)
cv.imshow("Before2", src2)
value(src1, src2)
logic(src1,src2)
cv.waitKey(0)
cv.destroyAllWindows()