Advertisement
Guest User

Untitled

a guest
May 1st, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. numberOfPyramids = 9
  2.  
  3. # generate Gaussian pyramids for A and B Images
  4. GA = A.copy()
  5. GB = B.copy()
  6. gpA = [GA]
  7. gpB = [GB]
  8.  
  9. for i in xrange(numberOfPyramids):
  10. GA = cv2.pyrDown(GA)
  11. GB = cv2.pyrDown(GB)
  12. gpA.append(GA)
  13. gpB.append(GB)
  14.  
  15. # generate Laplacian Pyramids for A and B Images
  16. lpA = [gpA[numberOfPyramids - 1]]
  17. lpB = [gpB[numberOfPyramids - 1]]
  18.  
  19. for i in xrange(numberOfPyramids - 1, 0, -1):
  20. geA = cv2.pyrUp(gpA[i], dstsize = np.shape(gpA[i-1])[:2])
  21. geB = cv2.pyrUp(gpB[i], dstsize = np.shape(gpB[i-1])[:2])
  22.  
  23. laplacianA = gpA[i - 1] - geA if i != 1 else cv2.subtract(gpA[i-1], geA)
  24. laplacianB = gpB[i - 1] - geB if i != 1 else cv2.subtract(gpB[i-1], geB)
  25.  
  26. lpA.append(laplacianA)
  27. lpB.append(laplacianB)
  28.  
  29. # Now add left and right halves of images in each level
  30. LS = []
  31. for la, lb in zip(lpA, lpB):
  32. _, cols, _ = la.shape
  33. ls = np.hstack((la[:, : cols / 2], lb[:, cols / 2 :]))
  34. LS.append(ls)
  35.  
  36. # now reconstruct
  37. ls_ = LS[0]
  38. for i in xrange(1, numberOfPyramids):
  39. ls_ = cv2.pyrUp(ls_, dstsize = np.shape(LS[i])[:2])
  40. ls_ = ls_ + LS[i] if i != numberOfPyramids - 1 else cv2.add(ls_, LS[i])
  41.  
  42. cv2.imshow(namedWindowName, ls_)
  43. cv2.waitKey()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement