Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- numberOfPyramids = 9
- # generate Gaussian pyramids for A and B Images
- GA = A.copy()
- GB = B.copy()
- gpA = [GA]
- gpB = [GB]
- for i in xrange(numberOfPyramids):
- GA = cv2.pyrDown(GA)
- GB = cv2.pyrDown(GB)
- gpA.append(GA)
- gpB.append(GB)
- # generate Laplacian Pyramids for A and B Images
- lpA = [gpA[numberOfPyramids - 1]]
- lpB = [gpB[numberOfPyramids - 1]]
- for i in xrange(numberOfPyramids - 1, 0, -1):
- geA = cv2.pyrUp(gpA[i], dstsize = np.shape(gpA[i-1])[:2])
- geB = cv2.pyrUp(gpB[i], dstsize = np.shape(gpB[i-1])[:2])
- laplacianA = gpA[i - 1] - geA if i != 1 else cv2.subtract(gpA[i-1], geA)
- laplacianB = gpB[i - 1] - geB if i != 1 else cv2.subtract(gpB[i-1], geB)
- lpA.append(laplacianA)
- lpB.append(laplacianB)
- # Now add left and right halves of images in each level
- LS = []
- for la, lb in zip(lpA, lpB):
- _, cols, _ = la.shape
- ls = np.hstack((la[:, : cols / 2], lb[:, cols / 2 :]))
- LS.append(ls)
- # now reconstruct
- ls_ = LS[0]
- for i in xrange(1, numberOfPyramids):
- ls_ = cv2.pyrUp(ls_, dstsize = np.shape(LS[i])[:2])
- ls_ = ls_ + LS[i] if i != numberOfPyramids - 1 else cv2.add(ls_, LS[i])
- cv2.imshow(namedWindowName, ls_)
- cv2.waitKey()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement