-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPA2-Part4.py
45 lines (32 loc) · 1.04 KB
/
PA2-Part4.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
34
35
36
37
38
39
40
41
42
43
44
45
import cv2
import numpy as np
import matplotlib
matplotlib.use("TkAgg")
from matplotlib import pyplot as plt
view1 = cv2.imread('view1.png')
view5 = cv2.imread('view5.png')
disp1 = cv2.imread('disp1.png', cv2.IMREAD_GRAYSCALE)
disp5 = cv2.imread('disp5.png', cv2.IMREAD_GRAYSCALE)
def view_synthesis():
height, width, rgb = view1.shape
view3 = np.zeros(view1.shape, dtype=np.uint8)
for row in range(height):
for col in range(width):
mid = disp1[row, col] / 2
if col - mid < 0:
continue
view3[row, int(col - mid)] = view1[row, col]
cv2.imwrite('view3_partial.jpg', view3)
for row in range(height):
for col in range(width):
mid = disp5[row, col] / 2
if col + mid >= width:
continue
if view3[row, int(col + mid)].all() == 0:
view3[row, int(col + mid)] = view5[row, col]
cv2.imwrite('view3_synthesized.jpg', view3)
return view3
def main():
view3 = view_synthesis()
return
main()