Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. apple = cv2.imread('C:\\Users\\quntu\\Desktop\\coding\\apple.jpg')
  2. orange = cv2.imread('C:\\Users\\quntu\\Desktop\\coding\\orange.jpg')
  3.  
  4. apple_copy = apple.copy()
  5. gaussian_pyramid_apple = [apple_copy]
  6. for i in range(6):
  7. apple_copy = cv2.pyrDown(apple_copy)
  8. gaussian_pyramid_apple.append(apple_copy)
  9.  
  10.  
  11. orange_copy = orange.copy()
  12. gaussian_pyramid_orange = [orange_copy]
  13. for i in range(6):
  14. orange_copy = cv2.pyrDown(orange_copy)
  15. gaussian_pyramid_orange.append(orange_copy)
  16.  
  17.  
  18. apple_copy = gaussian_pyramid_apple[5]
  19. lp_apple = [apple_copy]
  20. for i in range(5, 0, -1):
  21. gaussian_expanded = cv2.pyrUp(gaussian_pyramid_apple[i])
  22. laplacian = cv2.subtract(gaussian_pyramid_apple[i-1], gaussian_expanded)
  23. lp_apple.append(laplacian)
  24.  
  25.  
  26. orange_copy = gaussian_pyramid_orange[5]
  27. lp_orange = [orange_copy]
  28. for i in range(5, 0, -1):
  29. gaussian_expanded = cv2.pyrUp(gaussian_pyramid_orange[i])
  30. laplacian = cv2.subtract(gaussian_pyramid_orange[i-1], gaussian_expanded)
  31. lp_orange.append(laplacian)
  32.  
  33.  
  34.  
  35. apple_orange_pyramid = []
  36. n = 0
  37. for apple_lap, orange_lap in zip(lp_apple, lp_orange):
  38. n += 1
  39. cols, rows, channels = apple_lap.shape
  40. laplacian = np.hstack((apple_lap[:, 0:int(cols/2)], orange_lap[:, int(cols/2):]))
  41. apple_orange_pyramid.append(laplacian)
  42. cv2.imshow(str(n), laplacian)
  43.  
  44. apple_orange_reconstruct = apple_orange_pyramid[0]
  45.  
  46. for i in range(1, 6):
  47. apple_orange_reconstruct = cv2.pyrUp(apple_orange_reconstruct)
  48. apple_orange_reconstruct = cv2.add(apple_orange_pyramid[i], apple_orange_reconstruct)
  49.  
  50.  
  51.  
  52. cv2.imshow('reconstruct', apple_orange_reconstruct)
  53. cv2.waitKey(0)
  54. cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement