import cv2
import numpy as np
A = cv2.imread("./images/21.jpg")
B = cv2.imread("./images/22.jpg")
# 生成高斯A
G = A.copy()
gpA = [G]
for i in range(6):
G = cv2.pyrDown(G)
gpA.append(G)
# 生成高斯金字塔B
G = B.copy()
gpB = [G]
for i in range(6):
G = cv2.pyrDown(G)
gpB.append(G)
# 生成拉普拉斯金字塔A
lpA = [gpA[5]]
for i in range(5,0,-1):
GE = cv2.pyrUp(gpA[i])
L = cv2.subtract(gpA[i-1],GE)
lpA.append(L)
# 生成拉普拉斯B
lpB = [gpB[5]]
for i in range(5,0,-1):
GE = cv2.pyrUp(gpB[i])
L = cv2.subtract(gpB[i-1],GE)
lpB.append(L)
#
LS = []
for i,(la,lb) in enumerate(zip(lpA,lpB)):
rows,cols,dpt = la.shape
ls = np.hstack((la[:,0:cols//2],lb[:,cols//2:]))
LS.append(ls)
#
ls_ = LS[0]
for i in range(1,6):
ls_ = cv2.pyrUp(ls_)
ls_ = cv2.add(ls_,LS[i])
cv2.imshow(f"xxx{i}",ls_)
cv2.waitKey(0)