-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransform.py
75 lines (47 loc) · 1.51 KB
/
transform.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import numpy as np
from PIL import Image
import math
import pptk
def transform(file):
img = Image.open(file)
arr = np.array(img)
img.close()
arr = arr
width = arr.shape[0]
height = arr.shape[1]
theta_w = (35 / 180) * math.pi
theta_h = (90 / 180) * math.pi
alpha_w = 2 * math.pi - theta_w / 2
alpha_h = (math.pi - theta_h) / 2
res = []
for i in range(width):
for j in range(height):
gamma_h = alpha_h + j * (theta_h / height)
x = arr[i][j] / math.tan(gamma_h)
gamma_w = alpha_w + i * (theta_w / width)
y = arr[i][j] * math.tan(gamma_w)
if arr[i][j] != 0:
# res.append([arr[i][j],j, -i])
res.append([arr[i][j], x, -y])
res = np.array(res)
pptk.viewer(res)
def transform_array(arr):
width = arr.shape[0]
height = arr.shape[1]
theta_w = (35 / 180) * math.pi
theta_h = (90 / 180) * math.pi
alpha_w = 2 * math.pi - theta_w / 2
alpha_h = (math.pi - theta_h) / 2
res = []
for i in range(width):
for j in range(height):
gamma_h = alpha_h + j * (theta_h / height)
x = arr[i][j] / math.tan(gamma_h)
gamma_w = alpha_w + i * (theta_w / width)
y = arr[i][j] * math.tan(gamma_w)
# if arr[i][j] != 0:
# res.append([arr[i][j],j, -i])
res.append([arr[i][j], x, -y])
res = np.array(res)
# f = pptk.viewer(res)
return res