6、图片色素的数值运算(加减乘除)和逻辑运算(与或非异或)
作者:互联网
代码
解释都在注释里啦
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()
标签:p2,逻辑运算,imshow,bitwise,src2,异或,p1,cv,加减乘除 来源: https://blog.csdn.net/m0_51638853/article/details/115418622