import cv2
import numpy as np
# 圖像混合
img1 = cv2.imread('add1.png')# (380, 308, 3) #讀取圖片1
img2 = cv2.imread('add2.png')# (380, 308, 3) #讀取圖片2
dst = cv2.addWeighted(img1, 0.7, img2, 0.3, 0)
# 第一幅圖的權重是 0.7 第二幅圖的權重是 0.3。大概就是第二幅圖浮現加在第一個圖上
#g(x) = αf(x) + β,其中:α(>0)、β常稱爲增益與偏置值,分別控制圖片的對比度和亮度。
res = np.uint8(np.clip((1.5 * dst + 10), 0, 255)) # 1.5是對比度 10是亮度
cv2.imwrite("res.png",res) #保存
cv2.imshow('dst', res) #顯示
cv2.waitKey(0)
cv2.destroyAllWindows()