-
Notifications
You must be signed in to change notification settings - Fork 0
/
blend.py
33 lines (27 loc) · 990 Bytes
/
blend.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import cv2
import numpy as np
img = cv2.imread("A_1.png")
# Gaussian Pyramid
layer = img.copy()
gaussian_pyramid = [layer]
for i in range(6):
layer = cv2.pyrDown(layer)
gaussian_pyramid.append(layer)
print(img.shape)
# Laplacian Pyramid
layer = gaussian_pyramid[5]
laplacian_pyramid = [layer]
for i in range(5, 0, -1):
size = (gaussian_pyramid[i - 1].shape[1], gaussian_pyramid[i - 1].shape[0])
gaussian_expanded = cv2.pyrUp(gaussian_pyramid[i], dstsize=size)
laplacian = cv2.subtract(gaussian_pyramid[i - 1], gaussian_expanded)
laplacian_pyramid.append(laplacian)
print("Laplacian Pyramid")
print(len(laplacian_pyramid))
for img in laplacian_pyramid:
print(img.shape)
reconstructed_image = laplacian_pyramid[0]
for i in range(1, 6):
size = (laplacian_pyramid[i].shape[1], laplacian_pyramid[i].shape[0])
reconstructed_image = cv2.pyrUp(reconstructed_image, dstsize=size)
reconstructed_image = cv2.add(reconstructed_image, laplacian_pyramid[i])