-
Notifications
You must be signed in to change notification settings - Fork 7
/
Buddaha_improved.py
67 lines (46 loc) · 1.58 KB
/
Buddaha_improved.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
# coding: utf-8
from processing import *
from numpy import *
import matplotlib.pyplot as plt
I,mask,S = read_data_file("Data/Buddha.mat")
I_all = I.reshape(I.shape[0]*I.shape[1],10).T
from itertools import *
all_iter = [(i,j,k) for i in [0,1,2,3] for j in [4,5] for k in [6,7,8,9]]
num = 1
plt.figure(figsize=(8,8))
for i,j,k in all_iter:
I_choosen = vstack((I_all[i],I_all[j],I_all[k]))
S_choosen = vstack((S[i],S[j],S[k]))
M = linalg.pinv(S_choosen).dot(I_choosen)
M_1 = M[0]
M_2 = M[1]
M_3 = M[2]
rho = sqrt(M_1**2 + M_2**2 + M_3**2).reshape(I.shape[0],I.shape[1])
n_1 = (M_1 / rho.reshape(-1)).reshape(I.shape[0],I.shape[1])
n_2 = (M_2 / rho.reshape(-1)).reshape(I.shape[0],I.shape[1])
n_3 = (M_3 / rho.reshape(-1)).reshape(I.shape[0],I.shape[1])
z = unbiased_integrate(n_1,n_2,n_3,mask)
plt.subplot(8,4,num)
plt.imshow(z*mask)
plt.axis('off')
plt.title(num)
num += 1
# choose the all_iter[9]
i,j,k = all_iter[9]
I_choosen = vstack((I_all[i],I_all[j],I_all[k]))
S_choosen = vstack((S[i],S[j],S[k]))
M = linalg.inv(S_choosen).dot(I_choosen)
M_1 = M[0]
M_2 = M[1]
M_3 = M[2]
plt.figure()
rho = sqrt(M_1**2 + M_2**2 + M_3**2).reshape(I.shape[0],I.shape[1])
plt.imshow(rho,cmap = plt.cm.gray)
plt.title("2-D Image for albedo")
n_1 = (M_1 / rho.reshape(-1)).reshape(I.shape[0],I.shape[1])
n_2 = (M_2 / rho.reshape(-1)).reshape(I.shape[0],I.shape[1])
n_3 = (M_3 / rho.reshape(-1)).reshape(I.shape[0],I.shape[1])
z = unbiased_integrate(n_1,n_2,n_3,mask)
display_depth_matplotlib(z)
display_depth_mayavi(z)
plt.show()