-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreconstructions.py
105 lines (69 loc) · 2.62 KB
/
reconstructions.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from __future__ import print_function
import numpy as np
import matplotlib.pyplot as plt
from skimage.draw import ellipse
# -------------------------------------------------------------------------
fname = 'projections.npy'
print('Reading:', fname)
projections = np.load(fname)
print('projections:', projections.shape, projections.dtype)
# -------------------------------------------------------------------------
fname = 'signals_data.npy'
print('Reading:', fname)
signals_data = np.load(fname)
print('signals_data:', signals_data.shape, signals_data.dtype)
fname = 'signals_time.npy'
print('Reading:', fname)
signals_time = np.load(fname)
print('signals_time:', signals_time.shape, signals_time.dtype)
# -------------------------------------------------------------------------
P = projections.reshape((projections.shape[0], -1))
print('P:', P.shape, P.dtype)
# -------------------------------------------------------------------------
n_rows = projections.shape[1]
n_cols = projections.shape[2]
Dh = np.eye(n_rows*n_cols) - np.roll(np.eye(n_rows*n_cols), 1, axis=1)
Dv = np.eye(n_rows*n_cols) - np.roll(np.eye(n_rows*n_cols), n_cols, axis=1)
print('Dh:', Dh.shape, Dh.dtype)
print('Dv:', Dv.shape, Dv.dtype)
# -------------------------------------------------------------------------
ii, jj = ellipse(n_rows//2, n_cols//2, n_rows//2, n_cols//2)
mask = np.ones((n_rows, n_cols))
mask[ii,jj] = 0.
Io = np.eye(n_rows*n_cols) * mask.flatten()
print('Io:', Io.shape, Io.dtype)
# -------------------------------------------------------------------------
Pt = np.transpose(P)
PtP = np.dot(Pt, P)
DtDh = np.dot(np.transpose(Dh), Dh)
DtDv = np.dot(np.transpose(Dv), Dv)
ItIo = np.dot(np.transpose(Io), Io)
alpha_1 = 5e2
alpha_2 = alpha_1
alpha_3 = alpha_1*10
inv = np.linalg.inv(PtP + alpha_1*DtDh + alpha_2*DtDv + alpha_3*ItIo)
M = np.dot(inv, Pt)
# -------------------------------------------------------------------------
tomo = []
tomo_t = np.arange(0.310, 0.331, 0.001)
for t in tomo_t:
i = np.argmin(np.fabs(signals_time[0] - t))
f = signals_data[:,i].reshape((-1, 1))
g = np.dot(M, f)
tomo.append(g.reshape((n_rows, n_cols)))
tomo = np.array(tomo)
print('tomo:', tomo.shape, tomo.dtype)
print('tomo_t:', tomo_t.shape, tomo_t.dtype)
# -------------------------------------------------------------------------
vmin = 0.
vmax = np.max(tomo)
ni = 4
nj = tomo.shape[0]//ni
fig, ax = plt.subplots(ni, nj, figsize=(2*nj, 2*ni))
for i in range(ni):
for j in range(nj):
k = i*nj + j
ax[i,j].imshow(tomo[k], vmin=vmin, vmax=vmax)
ax[i,j].set_title('t=%.3fs' % tomo_t[k])
ax[i,j].set_axis_off()
plt.show()