-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathphase_calculator.py
More file actions
61 lines (42 loc) · 1.39 KB
/
phase_calculator.py
File metadata and controls
61 lines (42 loc) · 1.39 KB
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
"""
calculate phase by given phase gradient
"""
import numpy as np
def reconstruct_phase(gx, gy):
"""
reconstruct the final phase image using gx and gy
gx: differential phase gradient in x
gy: differential phase gradient in y
"""
gx = np.array(gx)
gy = np.array(gy)
shapev = gy.shape
print "shape is", shapev
row = shapev[0]
column = shapev[1]
totalnum = row*column
dx = 0.2 # in um
dy = 0.2
w = 1 # Weighting parameter
tx = np.fft.fftshift(np.fft.fft2(gx))
ty = np.fft.fftshift(np.fft.fft2(gy))
c = np.arange(totalnum, dtype=complex).reshape(row, column)
for i in range(row):
for j in range(column):
kappax = 2 * np.pi * (j+1-(np.floor(column/2.0)+1)) / (column*dx)
kappay = 2 * np.pi * (i+1-(np.floor(row/2.0)+1)) / (row*dy)
if kappax == 0 and kappay == 0:
c[i, j] = 0
else:
cTemp = -1j * (kappax*tx[i][j]+w*kappay*ty[i][j]) / (kappax**2 + w*kappay**2)
c[i, j] = cTemp
padv1 = row*2
padv2 = column*2
c_new = np.zeros([row+2*padv1,column+2*padv2], dtype=complex)
#c_new[padv1:-padv1, padv2:-padv2] = c
c_new = c
c_new = np.fft.ifftshift(c_new)
phi = np.fft.ifft2(c_new)
phi = phi.real
#imsave(namephi, self.phi)
return phi