# OpenCV-Python教程:17.图像金字塔

lower_reso = cv2.pyrDown(higher_reso)

higher_reso2 = cv2.pyrUp(lower_reso)

1.加载两张图片，苹果和桔子的。

2.找到苹果和桔子的高斯金字塔（在这个例子里，一共6级）

3.从高斯金字塔找到拉普拉斯金字塔

4.把左半个苹果和右半个桔子在拉普拉斯金字塔的每个级别合起来

5.最后从这些图像金字塔里重建出原始图像。

import cv2
import numpy as np, sys

# generate Gaussian pyramid for A
G = A.copy()
gpA = [G]
for i in xrange(6):
G = cv2.pyrDown(G)
gpA.append(G)

# generate Gaussian pyramid for B
G = B.copy()
gpB = [G]
for i in xrange(6):
G = cv2.pyrDown(G)
gpB.append(G)

# generate Laplacian Pyramid for A
lpA = [gpA[5]]
for i in xrange(5,0,-1):
GE = cv2.pyrUp(gpA[i])
L = cv2.subtract(gpA[i-1],GE)
lpA.append(L)

# generate Laplacian Pyramid for B
lpB = [gpB[5]]
for i in xrange(5,0,-1):
GE = cv2.pyrUp(gpB[i])
L = cv2.subtract(gpB[i-1],GE)
lpB.append(L)

# Now add left and right halves of images in each level
LS = []
for la, lb in zip(lpA,lpB):
rows, cols, dpt=la.shape
ls = np.hstack((la[:,0:cols/2],lb[:,cols/2:]))
LS.append(ls)

# now reconstruct
ls_ = LS[0]
for i in xrange(1,6):
ls_ = cv2.pyrUp(ls_)