2 import matplotlib.pyplot
as plt
5 from concurrent.futures
import ProcessPoolExecutor
15 @njit(nogil=
True, cache=
True)
17 return (np.pi * 2) / wvl
21 def h_RS(x1, y1, z1, x2, y2, z2, wvl, pp):
22 r = np.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2))
23 t = (wvl * r) / (2 * pp)
24 if (x1 - t < x2 < x1 + t)
and (y1 - t < y2 < y1 + t):
25 h_r = np.sin(
k(wvl) * r) / r ** 2
26 h_i = np.cos(
k(wvl) * r) / r ** 2
34 def h_Frsn(x1, y1, z1, x2, y2, z2, wvl, pp):
35 """impulse response function of Fresnel propagation method""" 37 r = ((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) / (2*z)
38 t = (wvl * z) / (2 * pp)
39 if (x1 - t < x2 < x1 + t)
and (y1 - t < y2 < y1 + t):
40 h_r = np.cos(
k(wvl) * r)
41 h_i = np.sin(
k(wvl) * r)
49 def Conv(x1, y1, z1, z2, amp, h, w, pp, wvl, method):
50 ch_r = np.zeros((h, w))
51 ch_i = np.zeros((h, w))
57 ch_r[i, j], ch_i[i, j] =
h_RS(x1, y1, z1, x2, y2, z2, wvl, pp)
59 ch_r[i, j], ch_i[i, j] =
h_Frsn(x1, y1, z1, x2, y2, z2, wvl, pp)
60 return (ch_r + 1j * ch_i) * amp
65 Get Fringe pattern by Point Cloud data(.ply) 68 plypath : .ply file path 69 angle : phase shift angle 70 Red, Green, Blue : wavelength of RGB color 71 scale : scaling factor 75 def __init__(self, plypath, method='RS', propagation_distance=1, angleX=0, angleY=0, Red=639*nm, Green=525*nm, Blue=463*nm,
76 SLM_width=3840, SLM_height=2160, scaleXY=0.03, scaleZ=0.25, pixel_pitch=3.6*um, multicore=True):
77 self.
z = propagation_distance
89 with open(plypath,
'rb')
as f:
93 self.
num_cpu = multiprocessing.cpu_count()
100 def Cal(self, n, color='red'):
104 elif color ==
'blue':
111 amp = self.
plydata[color][n] * (self.
z / wvl)
112 ch =
Conv(x0, y0, z0, self.
z, amp, self.
h, self.
w, self.
pp, wvl, self.
methods)
113 print(self.
methods,
'methods ', n,
' th point ', color,
' Done')
117 return self.
Cal(n,
'red')
120 return self.
Cal(n,
'green')
123 return self.
Cal(n,
'blue')
126 """Calculate hologram""" 129 elif color ==
'blue':
133 print(self.
num_cpu,
" core Ready")
134 ch = np.zeros((self.
h, self.
w), dtype=
'complex128')
138 with ProcessPoolExecutor(self.
num_cpu)
as ex:
139 cache = [result
for result
in ex.map(func, list(n))]
140 cache = np.asarray(cache)
141 print(n,
'steps done')
142 for j
in range(len(n)):
148 return np.fft.fftshift(np.fft.fft2(np.fft.fftshift(f)))
151 return np.fft.fftshift(np.fft.ifft2(np.fft.fftshift(f)))
154 """single side band encoding""" 155 height, width = ch.shape
156 a = np.zeros((height, width), dtype=
'complex128')
158 CH = CH[height // 4: (height * 3) // 4, :]
159 a[0:height // 2, :] = CH
160 a[height // 2:, :] = np.conj(CH)
166 arrin = np.copy(np.imag(arr))
168 arrin = np.copy(np.real(arr))
169 elif type ==
'angle':
170 arrin = np.copy(np.angle(arr))
171 elif type ==
'amplitude':
172 arrin = np.copy(np.abs(arr))
176 arrin -= np.min(arrin)
178 arrin = arrin / (np.max(arrin))
184 img = np.zeros((h, w, 3))
188 plt.imsave(fname, img)
192 """Get Single channel image""" 194 phase = fname +
'_IM.bmp' 195 plt.imsave(phase, im, cmap=
'gray')
197 real = fname +
'_RE.bmp' 198 plt.imsave(real, re, cmap=
'gray')
def h_RS(x1, y1, z1, x2, y2, z2, wvl, pp)
def normalize(self, arr, type='angle')
def Conv(x1, y1, z1, z2, amp, h, w, pp, wvl, method)
def Cal(self, n, color='red')
def getMonoImage(self, ch, fname)
def h_Frsn(x1, y1, z1, x2, y2, z2, wvl, pp)
def CalHolo(self, color='red')
def getRGBImage(self, R, G, B, fname, type='angle')
def __init__(self, plypath, method='RS', propagation_distance=1, angleX=0, angleY=0, Red=639 *nm, Green=525 *nm, Blue=463 *nm, SLM_width=3840, SLM_height=2160, scaleXY=0.03, scaleZ=0.25, pixel_pitch=3.6 *um, multicore=True)