def generate_holo_fromfield(particles_field): particles_field = particles_field.sort_values(by=['z'], ascending=False) s = get_size(size_range[0], size_range[1], len(particles_field)) particles_field['size'] = s z_list = particles_field['z'].unique() F_obj = Begin(frame_size, wavelength, N) for i in range(len(z_list) - 1): prop_dis = z_list[i] - z_list[i + 1] if prop_dis < 0: raise ValueError("z is not aceding") particles = particles_field[particles_field['z'] == z_list[i]] for j in range(len(particles)): F_obj = CircScreen(F_obj, particles.iloc[j]['size'], particles.iloc[j]['x'], particles.iloc[j]['y']) F_obj = ASM(F_obj, prop_dis) particles = particles_field[particles_field['z'] == z_list[-1]] for j in range(len(particles)): F_obj = CircScreen(F_obj, particles.iloc[j]['size'], particles.iloc[j]['x'], particles.iloc[j]['y']) F_obj = ASM(F_obj, z_list[-1]) I = Intensity(F_obj) # plt.imsave("Hologram%d.png" % n, I, cmap='gray') return I
def generate_holo_fromcsv2(file): particles_field = pd.read_csv(file) z_list = particles_field['z'].unique() F_obj = Begin(size, wavelength, N) for i in range(len(z_list) - 1): prop_dis = z_list[i] - z_list[i + 1] if prop_dis < 0: raise ValueError("z is not aceding") particles = particles_field[particles_field['z'] == z_list[i]] for j in range(len(particles)): F_obj = CircScreen(F_obj, particles.iloc[j]['size'], particles.iloc[j]['x'], particles.iloc[j]['y']) F_obj = ASM(F_obj, prop_dis) F_obj = ASM(F_obj, z_list[-1]) I = Intensity(F_obj) # plt.imsave("Hologram%d.png" % n, I, cmap='gray') return I
def generate_holo_fromcsv(file): particles_field = pd.read_csv(file) grouped = particles_field.groupby(by=['z']) F_ini = Begin(size, wavelength, N) F_obj_mix = F_ini count = 0 for z, particles in grouped: F_ini = Begin(size, wavelength, N) F_obj_new = F_ini for i in range(len(particles)): F_obj_new = CircScreen(F_obj_new, particles.iloc[i]['size'], particles.iloc[i]['x'], particles.iloc[i]['y']) F_obj_new = ASM(F_obj_new, z) F_obj_mix = BeamMix(F_obj_mix, F_obj_new) count += 1 I = Intensity(F_obj_mix) # plt.imsave("Hologram%d.png" % n, I, cmap='gray') return I
size = 10 * mm # 10mm * 10mm size_range = [20 * um, 100 * um] for n in range(10): t1 = time.time() # generate the random 3D location NUMBER = np.random.randint(low=50, high=200, dtype=int) Z_list = np.array(np.linspace(1 * cm, 3 * cm, 256)) particles = particle_field(NUMBER, size, Z_list, size_range=size_range) particles = particles.sort_values(by=['z'], ascending=False) particles.to_csv("Hologram%d.csv" % n, index=False) particles_field = pd.read_csv("Hologram%d.csv" % n) grouped = particles_field.groupby(by=['z']) F_ini = Begin(size, wavelength, N) F_obj_mix = F_ini for z, particles in grouped: F_ini = Begin(size, wavelength, N) for i in range(len(particles)): F_obj_new = CircScreen(F_ini, particles.iloc[i]['size'], particles.iloc[i]['x'], particles.iloc[i]['y']) F_obj_new = ASM(F_obj_new, z) F_obj_mix = BeamMix(F_obj_mix, F_obj_new) I = Intensity(F_obj_mix, 2) plt.imsave("Hologram%d.png" % n, I, cmap='gray') t2 = time.time() print('%5d / 1000 Time for hologram %f s with %d particle' % (n, (t2 - t1), NUMBER))
from propagators import ASM import numpy as np import pandas as pd import time wavelength = 633 * nm N = 1024 # pixel_pitch = 10*um size = 10 * mm # 10mm * 10mm size_range = [20 * um, 100 * um] depth_range = [1 * cm, 3 * cm] F = Begin(size, wavelength, N) F = CircScreen(F, size_range[0], 2.5 * mm, 2.5 * mm) F = CircScreen(F, size_range[1], -2.5 * mm, 2.5 * mm) F = ASM(F, 2 * cm) F = CircScreen(F, size_range[0], -2.5 * mm, -2.5 * mm) F = CircScreen(F, size_range[1], 2.5 * mm, -2.5 * mm) F = ASM(F, 1 * cm) I = Intensity(F) # plt.imshow(I,cmap='gray') plt.imsave("test.png", I, cmap='gray') frame = size def get_buffer(z, size): z_rate = (z - 1 * cm) / (3 * cm - 1 * cm) size_rate = (size - size_range[0]) / (size_range[1] - size_range[0]) p_size = int(size_range[1] / frame * N) buffer = p_size * 10 * (z_rate * 0.6 + size_rate * 0.4)
[x2,y2,z2] = [-3.0*mm,1.2*mm,3*cm] [x3,y3,z3] = [0.3*mm,0.3*mm,1*cm] f_factor1 = 2*particle**2/(wavelength*z1) f_factor2 = 2*particle**2/(wavelength*z2) f_factor3 = 2*particle**2/(wavelength*z3) #%% F = Begin(size,wavelength,N) F_obj1 = CircScreen(F,particle,x1,y1) F_obj2 = CircScreen(F,particle,x2,y2) F_obj3 = CircScreen(F,particle,x3,y3) t1 = time.time() F_obj1 = ASM(F_obj1,z1) t2 = time.time() print('The time for compute one propagation is {:.2f} s'.format(t2-t1)) F_obj2 = ASM(F_obj2,z2) F_obj3 = ASM(F_obj3,z3) Mix = BeamMix(F_obj1,F_obj2) Mix = BeamMix(Mix,F_obj3) I = Intensity(Mix) #255 plt.imshow(I,cmap='gray');plt.axis('off');plt.title("Spectrum method FFT+IFFT");plt.show() plt.imsave("ImageASM_1.png",I,cmap='gray') fig = plt.figure() ax1 = fig.add_subplot(221) ax2 = fig.add_subplot(222) ax3 = fig.add_subplot(223)
[x1, y1, z1] = [0, 0, 3 * cm] [x2, y2, z2] = [-3.0 * mm, 1.2 * mm, 2 * cm] [x3, y3, z3] = [0.3 * mm, 0.3 * mm, 1 * cm] f_factor1 = 2 * particle**2 / (wavelength * z1) f_factor2 = 2 * particle**2 / (wavelength * z2) f_factor3 = 2 * particle**2 / (wavelength * z3) #%% F = Begin(size, wavelength, N) F_obj1 = CircScreen(F, particle, x1, y1) F_obj2 = CircScreen(F, particle, x2, y2) F_obj3 = CircScreen(F, particle, x3, y3) t1 = time.time() F_obj1 = ASM(F_obj1, z1) t2 = time.time() print('The time for compute one propagation is {:.2f} s'.format(t2 - t1)) F_obj1 = ASM(F_obj1, abs(z1 - z2)) F_obj2 = MultIntensity(F_obj1, abs(F_obj2.field)) F_obj2 = ASM(F_obj2, abs(z2 - z3)) F_obj3 = MultIntensity(F_obj2, abs(F_obj3.field)) F_obj3 = ASM(F_obj3, z3) # # F_obj3 = ASM(F_obj3,z3) # Mix = BeamMix(F_obj1,F_obj2) # Mix = BeamMix(Mix,F_obj3) I = Intensity(F_obj3) # 255 plt.imshow(I, cmap='gray')