高斯上采样
import cv2
img = cv2.imread("./images/13.jpg")
for i in range(3):
cv2.imshow(f"img{i}",img)
img = cv2.pyrUp(img)
cv2.waitKey(0)
高斯下采样
import cv2
img = cv2.imread("./images/13.jpg")
for i in range(3):
cv2.imshow(f"img{i}",img)
img = cv2.pyrDown(img)
cv2.waitKey(0)
import cv2
img = cv2.imread("./images/12.jpg")
img_down = cv2.pyrDown(img)
img_up = cv2.pyrUp(img_down)
img_new = cv2.subtract(img,img_up)
img_new = cv2.convertScaleAbs(img_new,alpha=5,beta=0)
cv2.imshow("img_LP",img_new)
cv2.waitKey(0)
图像融合实现
- 把苹果和梨放在一起
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)