Exemplo n.º 1
0
simRes, simFov = ms.pad(res, fov, padding)

ps = [0, 0, 0]              # position of the sphere
k_dir = [0, 0, -1]          # propagation direction of the plane wave
E = [1, 0, 0]               # electric field vector
E0 = 1

#%%
# get 1-D far field
E_far_line = ms.far_field(simRes, simFov, working_dis, a, n, 
                          lambDa, k_dir, scale_factor, dimension=1)
# get 1-D near line without bandpass filtering
E_near_line, E_near_x = ms.idhf(simRes, simFov, E_far_line)
# get 1-D bandpass filter
bpf_line = ms.bandpass_filter(simRes, simFov, NA_in, NA_out, dimension=1)
# get 1-D near field and its sample index
E_near_line_bp, E_near_x_bp = ms.apply_filter(simRes, simFov,
                                              E_far_line, bpf_line)
# far field with incident plane wave
F = E_near_line_bp + E0

#%%

# get ground truth from a 2-D simulation
# get far field
E_far = ms.far_field(simRes, simFov, working_dis, a, n,
                     lambDa, k_dir, scale_factor)
# get near field
E_near = ms.far2near(E_far) + E0
# get bandpass filter
Exemplo n.º 2
0
# pre-calculate the scatter matrix and the incident field
scatter = ms.scatter_matrix(simRes, simFov, working_dis, a_max, lambDa, k_dir,
                            1, 'far')

# allocate space for data set
sphere_data = np.zeros((3, num, num, num, num_bp))
im_data = np.zeros((line_size, 2, num, num, num, num_bp))
im_dir = r'D:\irimages\irholography\CNN\data_v12_far_line\more_bandpass_HD\im_data'

# get all the bandpass filters
bpfs = []
for b in range(num_bp):

    bp0 = bp[b]
    bpf = ms.bandpass_filter(simRes, simFov, 0, bp0, dimension=1)
    bpfs.append(bpf)

cnt = 0
for h in range(num):
    for i in range(num):
        for j in range(num):

            a0 = a[h]
            n0 = nr[i] + 1j * ni[j]

            B = ms.coeff_b(l, k, n0, a0)

            # integrate through all the orders to get the farfield in the Fourier Domain
            E_scatter_fft = np.sum(scatter * B, axis=-1) * scale_factor
Exemplo n.º 3
0
NA_in = 0.3
NA_out = 0.6

ps = [0, 0, 0]              # position of the sphere
k_dir = [0, 0, -1]          # propagation direction of the plane wave
E = [1, 0, 0]               # electric field vector
E0 = 1
#%%
# get far field
E_far = ms.far_field(simRes, simFov, working_dis, a, n, lambDa, scale_factor)

# get near field
E_near = ms.far2near(E_far) + E0

# get bandpass filter
bpf = ms.bandpass_filter(simRes, simFov, NA_in, NA_out)

# get bandpassed image
E_bp = ms.apply_filter(simRes, simFov, E_near, bpf)

# crop the image
E_crop = ms.crop_field(res, E_bp)

# Fourier axis
fx_axis = np.fft.fftshift(np.fft.fftfreq(simRes, simFov/simRes))

#%%
plt.figure()
plt.set_cmap('RdYlBu')
plt.subplot(121)
plt.imshow(np.real(E_bp), extent = [-simFov/2, simFov/2, -simFov/2, simFov/2])
Exemplo n.º 4
0
#%%
# load data set

raw_im = np.load(
    r'D:\irimages\irholography\CNN\data_v9_far_field\raw_data\im_data010.npy')
raw_im = np.reshape(raw_im, (640, 640, 2, 400))

raw_im = np.swapaxes(raw_im, 0, -1)
raw_im = np.swapaxes(raw_im, -2, -1)

data_dir = r'D:\irimages\irholography\CNN\data_v9_far_field'

#%%
num_test = 400
lambDa = 1
NA_in = 0
NA_out = 0.25
res = 128
fov = 16
padding = 2
simRes, simFov = ms.pad(res, fov, padding)

# create a bandpass filter
bpf = ms.bandpass_filter(simRes, simFov, NA_in, NA_out, dimension=2)
# apply bandpass filtering to all the images
im_bp_comp, im_bp_inten = bandpass_filtering(raw_im, bpf)

#%%
# create an animation
animation.anime(im_bp_inten, 20, data_dir, 'intensityBP0.25', 'Real')
intensity_CNN = load_model(
    r'D:\irimages\irholography\CNN\CNN_v12_far_field_a_n\intensity\intensity_model30.h5'
)

# parent directory of the data set
data_dir = r'D:\irimages\irholography\CNN\data_v10_far_field\split_data\test'

# allocate space for complex and intensity accuracy
complex_error = np.zeros((nb_NA, 3), dtype=np.float64)
intensity_error = np.zeros((nb_NA, 3), dtype=np.float64)

# for each NA to be tested
for NA_idx in range(nb_NA):

    # calculate the band pass filter
    bpf = ms.bandpass_filter(simRes, simFov, NA_in, NA_list[NA_idx])

    # print some info about the idx of NA
    print('Banbpassing the ' + str(NA_idx + 1) + 'th filter \n')
    im_data_complex, im_data_intensity = bandpass_filtering(bpf)

    print('Evaluating complex model \n')
    # handle complex model first
    complex_error[NA_idx, :] = calculate_error(im_data_complex,
                                               option='complex')

    print('Evaluating intensity model \n')
    # handle intensity model second
    intensity_error[NA_idx, :] = calculate_error(im_data_intensity,
                                                 option='intensity')
Exemplo n.º 6
0
    X_test = np.zeros((num_test_ds, line_size, 2))
    X_test_absolute = np.zeros((num_test_ds, line_size, 1))

    print('Banbpassing the ' + str(NA_idx + 1) + 'th filter \n')
    cnt = 0
    for idx in range(num_test_ds):

        n = y_test_ds[idx, 0] + 1j * y_test_ds[idx, 1]
        a = y_test_ds[idx, 2]

        B = ms.coeff_b(l, k, n, a)

        # integrate through all the orders to get the farfield in the Fourier Domain
        E_scatter_fft = np.sum(scatter * B, axis=-1) * scale_factor

        bpf_line = ms.bandpass_filter(simRes, simFov, 0, NA, dimension=1)

        # convert back to spatial domain
        E_near_line, E_near_x = ms.idhf(simRes, simFov,
                                        E_scatter_fft * bpf_line)

        E_near_line = (E_near_line -
                       np.mean(E_near_line)) / np.std(E_near_line)

        # shift the scattering field in the spacial domain for visualization
        Et = E_near_line + 1

        X_test[idx, :, 0] = np.real(Et)
        X_test[idx, :, 1] = np.imag(Et)

        X_test_absolute[idx, :, 0] = np.abs(Et)
# allocate space for data set
sphere_data = np.zeros((3, num, num, num, num_bp))
im_data = np.zeros((line_size, 2, num, num, num, num_bp))
im_dir = r'D:\irimages\irholography\CNN\data_v12_far_line\more_bandpass_HD\im_data'

# get all the bandpass filters
bpfs = []
for b in range(num_bp):
                
    bp0 = bp[b]

    bpf = get_bpf(simFov, simRes, 0, bp0)
    bpf_line = bpf[0, :int(simRes/2)+1]
    
    bpf_line0 = ms.bandpass_filter(simRes, simFov, 0, bp0, dimention=1)
    
    bpfs.append(bpf_line)

cnt = 0
for h in range(num):
    for i in range(num):
        for j in range(num):
            
            a0 = a[h]
            n0 = nr[i] + 1j*ni[j]
            
            B = coeff_b(l, k, n0, a0)

            # integrate through all the orders to get the farfield in the Fourier Domain
            E_scatter_fft = np.sum(scatter_matrix * B, axis = -1) * scale_factor