import cv2
import numpy as np
__author__ = "zxsuperstar"
__email__ = "[email protected]"
"""
图像的像素运算
cv2.add(src1, src2, dst=None, mask=None, dtype=None) 加运算函数
cv2.subtract(src1, src2, dst=None, mask=None, dtype=None) 减运算函数
src1:图像矩阵1
src1:图像矩阵2
dst: 默认选项
mask:默认选项
dtype:默认选项
cv2.bitwise_and(src1, src2, dst=None, mask=None) 取交集
cv2.bitwise_or(src1, src2, dst=None, mask=None) 取并集
src1:图像矩阵1
src1:图像矩阵2
dst: 默认选项
mask:默认选项
cv2.bitwise_not(src1, src2, dst=None, mask=None) 取反
src1:图像矩阵1
src1:图像矩阵2
dst: 默认选项
mask:默认选项
"""
def add_demo(m1,m2): # 加
dst = cv2.add(m1,m2)
cv2.imshow("add_demo",dst)
def subtract_demo(m1,m2): #减
dst = cv2.subtract(m1,m2)
cv2.imshow("subtract_demo",dst)
def divide_demo(m1,m2): #除
dst = cv2.divide(m1,m2)
cv2.imshow("divide_demo",dst)
def multiply_demo(m1,m2): #除
dst = cv2.multiply(m1,m2)
cv2.imshow("multiply_demo",dst)
def logic_demo(m1,m2): # 与运算
dst = cv2.bitwise_and(m1,m2) # 与运算
dst = cv2.bitwise_or(m1, m2) # 或运算
dst = cv2.bitwise_not(m1) # 非运算
cv2.imshow("logic", dst)
def contract_brightness_demo(image,c,b): # 亮度对比
h, w,ch = image.shape
blank = np.zeros([h,w,ch],image.dtype)
dst = cv2.addWeighted(image,c,blank,1-c,b)
cv2.imshow("con_b",dst)
def others(m1,m2):
m1 = cv2.mean(m1) #均值
m2 = cv2.mean(m2)
m1,dev1 = cv2.meanStdDev(m1) #方差
m2, dev1 = cv2.meanStdDev(m2)
print(m1,m2)
if __name__ == "__main__":
src1 = cv2.imread("t1.jpg") #blue green red
src2 = cv2.imread("t2.jpg")
cv2.namedWindow("image1", cv2.WINDOW_AUTOSIZE)
cv2.imshow("image1",src1)
cv2.imshow("image2",src2)
contract_brightness_demo(src2,1.2,10)
# add_demo(src1,src2)
# subtract_demo(src1,src2)
# divide_demo(src1,src2)
# multiply_demo(src1,src2)
# others(src1,src2)
# logic_demo(src1,src2)
cv2.waitKey(0)
cv2.destroyAllWindows()