-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3d_image_plane_and_distortion.py
101 lines (57 loc) · 2.25 KB
/
3d_image_plane_and_distortion.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
76
77
78
79
80
81
82
83
84
85
86
87
88
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(15,5))
def plot_image_plane(x: np.ndarray, y: np.ndarray) -> None:
#first plot - Image plane
ax = fig.add_subplot(131, projection='3d')
X, Y = np.meshgrid(x, y)
Z = np.zeros((np.max(x)+1, np.max(y)+1))
ax.plot_surface(X, Y, Z,cmap='magma')
plt.colorbar(ax.plot_surface(X, Y, Z, cmap='magma'), ax=ax, orientation='vertical',shrink=0.5, aspect=15, pad = 0.2)
def plot_r_sqr_plane(x: np.ndarray, y: np.ndarray, cx: int, cy: int) -> None:
#second Plot - r sqr plane
ay = fig.add_subplot(132, projection='3d')
nx, ny = (x-cx)/cx, (y-cy)/cx
r = np.sqrt((nx)**2 + (ny)**2)
NX,NY = np.meshgrid(nx, ny)
Z = np.sqrt((NX)**2 + (NY)**2)
Z2 = Z**2
#display the surface plot
ay.plot_surface(NX, NY, Z2,cmap='magma')
plt.colorbar(ay.plot_surface(NX, NY, Z2, cmap='magma'), ax=ay, orientation='vertical',shrink=0.5, aspect=15, pad = 0.2)
ay.set_xlabel('x\'')
ay.set_ylabel('y\'')
ay.set_zlabel('r2')
def plot_distortion_image_plane(x: np.ndarray, y: np.ndarray, cx: int, cy: int):
#thrid plot - distorted image plane
az = fig.add_subplot(133, projection='3d')
nx, ny = (x-cx)/cx, (y-cy)/cx
r = np.sqrt((nx)**2 + (ny)**2)
NX,NY = np.meshgrid(nx, ny)
k1 = 0.1
k2 = 0.01
k3 = 0.01
NX2, NY2 = NX * (1 + k1 * r**2), NY * (1 + k1 * r**2)
#NX2, NY2 = NX * (1 + k1 * r**2 + k2 * r**4 + k3 * r**6), NY * (1 + k1 * r**2 + k2 * r**4 + k3 * r**6)
Z = np.abs(np.sqrt((NX2 - NX)**2 + (NY2 - NY)**2))
print(np.max(Z))
print(np.min(Z))
# Label the axes
az.set_xlabel('x\'')
az.set_ylabel('y\'')
az.set_zlabel('|M|')
az.plot_surface(NX, NY, Z, cmap='magma')
plt.colorbar(az.plot_surface(NX, NY, Z, cmap='magma'), ax=az, orientation='vertical',shrink=0.5, aspect=15, pad = 0.2)
plt.show()
def main() -> None:
image_width : int = 4096
image_height : int = 4096
cx : int = image_width//2
cy : int = image_height//2
x = np.arange(0,image_width)
y = np.arange(0,image_height)
plot_image_plane(x,y)
plot_r_sqr_plane(x,y,cx,cy)
plot_distortion_image_plane(x,y,cx,cy)
if __name__ == "__main__":
main()