tf_fwd = muscat.computeconvolution(muscat.TF_ATF, myfac=myfac, myabsnorm=myabsnorm) #%% ''' Compute a first guess based on the experimental phase ''' init_guess = np.ones(matlab_val.shape) # np.angle(matlab_val)## #init_guess = init_guess-np.min(init_guess) init_guess = dn * init_guess / np.max( init_guess) + muscat.nEmbb #*dn+1j*.01*np.ones(init_guess.shape) if (0): mydiameter = 5 obj = tf_go.generateObject(mysize=muscat.mysize, obj_dim=muscat.dx, obj_type='sphere', diameter=mydiameter, dn=dn) #)dn) obj_absorption = tf_go.generateObject(mysize=muscat.mysize, obj_dim=muscat.dx, obj_type='sphere', diameter=mydiameter, dn=.01) init_guess = muscat.nEmbb + obj + 1j * obj_absorption * 0 #%% '''# Estimate the Phase difference between Measurement and Simulation''' # This is actually a crucial step and needs to be used with care. We don't want any phase wrappings ! '''Numpy to Tensorflow''' np_meas = matlab_val #np_mean = 1#np.mean(np_meas) #np_meas = np_meas/np_mean
#muscat.Nx = 64; muscat.Ny = 64; muscat.Nz = 70 #muscat.dz = muscat.lambda0/4 #muscat.Nz = 36 mymatfile = '/Users/bene/Dropbox/Dokumente/Promotion/PROJECTS/BOSTON/MUSCAT/MATLAB/MuScat/mtfs.mat' matatf = data.import_realdata_h5(filename = mymatfile, matname='myatf', is_complex=True) matasf = data.import_realdata_h5(filename = mymatfile, matname='myasf', is_complex=True) ''' Adjust some parameters to fit it in the memory ''' muscat.mysize = (muscat.Nz,muscat.Nx,muscat.Ny) # ordering is (Nillu, Nz, Nx, Ny) ''' Create a 3D Refractive Index Distributaton as a artificial sample''' mydiameter = 5 if(1): obj_real= tf_go.generateObject(mysize=muscat.mysize, obj_dim=1, obj_type ='sphere', diameter = mydiameter, dn = dn, nEmbb = muscat.nEmbb)#)dn) obj_absorption = tf_go.generateObject(mysize=muscat.mysize, obj_dim=1, obj_type ='sphere', diameter = mydiameter, dn = .0, nEmbb = 0.01) elif(1): obj_real = tf_go.generateObject(mysize=muscat.mysize, obj_dim=1, obj_type ='hollowsphere', diameter = mydiameter, dn = dn, nEmbb = muscat.nEmbb)#)dn) obj_absorption = tf_go.generateObject(mysize=muscat.mysize, obj_dim=muscat.dx, obj_type ='sphere', diameter = mydiameter, dn = .0) elif(0): obj_real= tf_go.generateObject(mysize=muscat.mysize, obj_dim=muscat.dx, obj_type ='twosphere', diameter = mydiameter/8, dn = dn)#)dn) obj_absorption = tf_go.generateObject(mysize=muscat.mysize, obj_dim=muscat.dx, obj_type ='twosphere', diameter = mydiameter/8, dn = .0) elif(0): obj_real= tf_go.generateObject(mysize=muscat.mysize, obj_dim=muscat.dx, obj_type ='foursphere', diameter = mydiameter/8, dn = dn)#)dn) obj_absorption = tf_go.generateObject(mysize=muscat.mysize, obj_dim=muscat.dx, obj_type ='foursphere', diameter = mydiameter/8, dn = .00) elif(0): obj_real= tf_go.generateObject(mysize=muscat.mysize, obj_dim=muscat.dx, obj_type ='eightsphere', diameter = mydiameter/8, dn = dn)#)dn) obj_absorption = tf_go.generateObject(mysize=muscat.mysize, obj_dim=muscat.dx, obj_type ='eightsphere', diameter = mydiameter/8, dn = .01) elif(0): # load a neuron
muscat.shiftIcX = experiments.shiftIcX muscat.NAc = experiments.NAc ''' Adjust some parameters to fit it in the memory ''' muscat.mysize = (muscat.Nz, muscat.Nx, muscat.Ny ) # ordering is (Nillu, Nz, Nx, Ny) # introduce zernike factors here muscat.zernikefactors = experiments.zernikefactors muscat.zernikemask = experiments.zernikemask ''' Compute a first guess based on the experimental phase ''' obj_guess = np.zeros(matlab_val.shape) + muscat.nEmbb # np.angle(matlab_val)## import src.tf_generate_object as tf_go mydiameter = 5 obj_guess = tf_go.generateObject(mysize=muscat.mysize, obj_dim=1, obj_type='sphere', diameter=mydiameter, dn=.05, nEmbb=1.33) #)dn) n_r = obj_guess #obj.astype("float32") / np.max(obj) * NumPhot k02 = (2 * np.pi * muscat.nEmbb / muscat.lambda0)**2 V = (k02 / (4 * np.pi)) * (n_r**2 - muscat.nEmbb**2) ''' Compute the systems model''' # Compute the System's properties (e.g. Pupil function/Illumination Source, K-vectors, etc.)¶ muscat.computesys(obj=obj_guess, is_compute_psf='BORN', is_dampic=.02) ''' Create Model Instance''' muscat.computemodel() print('Start Session') sess = tf.Session() sess.run(tf.global_variables_initializer())
''' Create the Model''' muscat = mus.MuScatModel(matlab_pars, is_optimization=is_optimization, is_optimization_psf = is_optimization_psf) muscat.Nx,muscat.Ny = int(np.squeeze(matlab_pars['Nx'].value)), int(np.squeeze(matlab_pars['Ny'].value)) muscat.shiftIcY=0 muscat.shiftIcX=0 muscat.dn = dn #muscat.NAc =.4 muscat.dz = muscat.lambda0/4 print('Attention: Changed Z-sampling!!') ''' Adjust some parameters to fit it in the memory ''' muscat.mysize = (muscat.Nz,muscat.Nx,muscat.Ny) # ordering is (Nillu, Nz, Nx, Ny) ''' Create a 3D Refractive Index Distributaton as a artificial sample''' obj = tf_go.generateObject(mysize=muscat.mysize, obj_dim=muscat.dx, obj_type ='sphere', diameter = , dn = muscat.dn) # introduce zernike factors here muscat.zernikefactors = zernikefactors ''' Compute the systems model''' muscat.computesys(obj, is_zernike=True) tf_fwd = muscat.computemodel() if(is_display): plt.subplot(131), plt.title('Ic'), plt.imshow(muscat.Ic) plt.subplot(132), plt.title('Po'),plt.imshow(np.fft.fftshift(np.abs(muscat.Po))), plt.colorbar() plt.subplot(133), plt.title('Po'),plt.imshow(np.fft.fftshift(np.angle(muscat.Po))), plt.colorbar(), plt.show()
muscat.Nx, muscat.Ny = int(np.squeeze(matlab_pars['Nx'].value)), int( np.squeeze(matlab_pars['Ny'].value)) muscat.shiftIcY = shiftIcY muscat.shiftIcX = shiftIcX muscat.dn = dn muscat.NAc = NAc #muscat.lambdaM = .7 #muscat.dz = muscat.lambdaM/4 #print('Attention: Changed Z-sampling!!') ''' Adjust some parameters to fit it in the memory ''' muscat.mysize = (muscat.Nz, muscat.Nx, muscat.Ny ) # ordering is (Nillu, Nz, Nx, Ny) ''' Create a 3D Refractive Index Distributaton as a artificial sample''' obj = tf_go.generateObject(mysize=muscat.mysize, obj_dim=(muscat.dz, muscat.dx, muscat.dy), obj_type='sphere', diameter=1, dn=muscat.dn) # introduce zernike factors here muscat.zernikefactors = zernikefactors # Compute the System's properties (e.g. Pupil function/Illumination Source, K-vectors, etc.)¶ ''' Compute the systems model''' muscat.computesys(obj, is_zernike=True, is_padding=is_padding, dropout_prob=1) print(muscat.Ic.shape) # Generate Computational Graph (fwd model) tf_fwd = muscat.computemodel() # Define Optimizer and Cost-function
muscat.dn = dn muscat.NAc = NAc #muscat.dz = muscat.lambda0/2 ''' Adjust some parameters to fit it in the memory ''' muscat.mysize = (muscat.Nz, muscat.Nx, muscat.Ny ) # ordering is (Nillu, Nz, Nx, Ny) # introduce zernike factors here muscat.zernikefactors = zernikefactors muscat.zernikemask = zernikemask ''' Compute the systems model''' # Compute the System's properties (e.g. Pupil function/Illumination Source, K-vectors, etc.)¶ mydiameter = 10 obj_real = tf_go.generateObject(mysize=muscat.mysize, obj_dim=muscat.dx, obj_type='sphere', diameter=mydiameter, dn=dn, nEmbb=muscat.nEmbb) #)dn) obj_absorption = tf_go.generateObject(mysize=muscat.mysize, obj_dim=muscat.dx, obj_type='sphere', diameter=mydiameter, dn=.0, nEmbb=0) obj = obj_real + 1j * obj_absorption muscat.computesys(obj=obj, is_padding=is_padding, mysubsamplingIC=mysubsamplingIC, is_compute_psf='corr') ''' Create Model Instance''' muscat.computemodel()
1.) Read in the parameters of the dataset ''' matlab_par_name = 'myParameter' #'./Data/DROPLETS/myParameterNew.mat';matname='myParameterNew' #'./Data/DROPLETS/myParameterNew.mat' matlab_par_file = './Data/DROPLETS/S19_multiple/Parameter.mat'; matname='myParameter' matlab_pars = data.import_parameters_mat(filename = matlab_par_file, matname=matlab_par_name) ''' Create a 3D Refractive Index Distributaton as a artificial sample 2.) Read in the virtual sample ''' # Fake Cheek-Cell matlab_val_file = './Data/PHANTOM/HeLa_cell_mat_obj.mat'; matname='HeLa_cell_mat' obj_real = data.import_realdata_h5(filename = matlab_val_file, matname=matname) if(0): mysize = np.array((128,128,128)) mydiameter=1 obj_real= tf_go.generateObject(mysize=mysize, obj_dim=1, obj_type ='twosphere', diameter = mydiameter, dn = .02, nEmbb = 1.33)#)dn) #TF_obj = tf.cast(tf.complex(obj_real,obj_real*0), tf.complex64) TF_obj = tf.cast(tf.placeholder_with_default(obj_real, obj_real.shape), tf.complex64) # etract scattering subroi-region mysize = obj_real.shape mysize_sub = ((32,32,32)); mycenter = ((mysize[0]//2,mysize[1]//2,mysize[1]//2)) # Region around the nuclei TF_obj_sub = tf_helper.extract((TF_obj-1.33)*2*np.pi, mysize_sub, mycenter) ''' Create the Model''' muscat = mus.MuScatModel(matlab_pars, is_optimization=is_optimization) muscat_sub = mus.MuScatModel(matlab_pars, is_optimization=is_optimization) # some adjustments of global model
init_guess = init_guess - np.min(init_guess) init_guess = dn * init_guess / np.max( init_guess) #*dn+1j*.01*np.ones(init_guess.shape) ''' Create a 3D Refractive Index Distributaton as a artificial sample''' #for sphere5 mydiameter = 3 obj = matlab_val squeezefac = muscat.dx / muscat.dz obj = ( ((squeezefac * tf_helper.xx(mysize=obj.shape)**2) + (tf_helper.yy(mysize=obj.shape)**2) + (squeezefac * tf_helper.zz(mysize=obj.shape)**2)) < (mydiameter**2) ) * dn #tf_go.generateObject(mysize=obj.shape, obj_dim=muscat.dx, obj_type ='sphere', diameter = mydiameter, dn = dn) obj_absorption = tf_go.generateObject(mysize=obj.shape, obj_dim=muscat.dx, obj_type='sphere', diameter=mydiameter, dn=.01) obj = obj + 1j * obj_absorption obj = np.roll(obj, 5, 0) # z obj = np.roll(obj, -3, 1) # y obj = np.roll(obj, 1, 2) # x init_guess = obj if (False): init_guess = matlab_val init_guess = dn * np.angle(init_guess) - np.min(np.angle(init_guess)) init_guess = init_guess / np.max(init_guess) * dn + 1j * .01 * np.ones( init_guess.shape) plt.subplot(231), plt.imshow(np.real(
''' Create the Model''' muscat = mus.MuScatModel(myparams, is_optimization=is_optimization) # optional: assign some external paramters which are not in the simulation file muscat.zernikefactors = experiments.zernikefactors# introduce zernike factors here muscat.zernikemask = experiments.zernikemask # this is only important for optimization #muscat.zernikefactors = np.array((0,0,0,0,0,0,.1,-1,0,0,-2)) # 7: ComaX, 8: ComaY, 11: Spherical Aberration #%% ''' Create a 3D Refractive Index Distributaton as a artificial sample''' mydiameter = 1 objtype = 'sphere'#'cheek100' # 'sphere', 'twosphere', 'slphantom' if(objtype == 'sphere'): obj_real= tf_go.generateObject(mysize=myparams.mysize, obj_dim=np.array((myparams.dz, myparams.dx, myparams.dy)), obj_type ='sphere', diameter = mydiameter, dn = experiments.dn, nEmbb = myparams.nEmbb)#)dn) obj_absorption= tf_go.generateObject(mysize=myparams.mysize, obj_dim=np.array((myparams.dz, myparams.dx, myparams.dy)), obj_type ='sphere', diameter = mydiameter, dn = .01, nEmbb = 0.)#)dn) elif(0): obj_real = tf_go.generateObject(mysize=myparams.mysize, obj_dim=1, obj_type ='hollowsphere', diameter = mydiameter, dn = experiments.dn, nEmbb = myparams.nEmbb)#)dn) obj_absorption = tf_go.generateObject(mysize=myparams.mysize, obj_dim=muscat.dx, obj_type ='sphere', diameter = mydiameter, dn = .0) elif(0): obj_real= tf_go.generateObject(mysize=myparams.mysize, obj_dim=1, obj_type ='twosphere', diameter = mydiameter, dn = experiments.dn, nEmbb = myparams.nEmbb) obj_absorption = tf_go.generateObject(mysize=myparams.mysize, obj_dim=muscat.dx, obj_type ='twosphere', diameter = mydiameter, dn = .0) elif(0): obj_real= tf_go.generateObject(mysize=myparams.mysize, obj_dim=muscat.dx, obj_type ='foursphere', diameter = mydiameter/8, dn = experiments.dn)#)dn) obj_absorption = tf_go.generateObject(mysize=myparams.mysize, obj_dim=muscat.dx, obj_type ='foursphere', diameter = mydiameter/8, dn = .00) elif(0): obj_real= tf_go.generateObject(mysize=myparams.mysize, obj_dim=muscat.dx, obj_type ='eightsphere', diameter = mydiameter/8, dn = experiments.dn)#)dn) obj_absorption = tf_go.generateObject(mysize=myparams.mysize, obj_dim=muscat.dx, obj_type ='eightsphere', diameter = mydiameter/8, dn = .01) elif(0): # load a neuron
myparams = paras.MyParameter() myparams.loadExperiment(experiments) myparams.print() # reset default graph tf.reset_default_graph() ''' Create the Model''' muscat = mus.MuScatModel(myparams, is_optimization=is_optimization) ''' Create a 3D Refractive Index Distributaton as a artificial sample''' mydiameter = 1 objtype = 'sphere' # 'cheek100'#'cheek100' # 'sphere', 'twosphere', 'slphantom' if (objtype == 'sphere'): obj_real = tf_go.generateObject(mysize=myparams.mysize, obj_dim=np.array((myparams.dz, myparams.dx, myparams.dy)), obj_type='sphere', diameter=mydiameter, dn=experiments.dn, nEmbb=myparams.nEmbb) #)dn) obj_absorption = tf_go.generateObject(mysize=myparams.mysize, obj_dim=np.array( (myparams.dz, myparams.dx, myparams.dy)), obj_type='sphere', diameter=mydiameter, dn=.01, nEmbb=0.) #)dn) elif (objtype == 'cheek100'): # Fake Cheek-Cell matlab_val_file = './Data/PHANTOM/HeLa_cell_mat_obj_100.mat' matname = 'HeLa_cell_mat'
# In[ ]: # Load Copute the systems model #if(load_data): # mm.loadData() #else: # mm.allSumAmp_mes = matlab_val # # ## Generate a phantom object in 3D # In[ ]: ''' Create a 3D Refractive Index Distributaton as a artificial sample''' obj = tf_go.generateObject(mysize=mm.mysize, obj_dim=mm.dx, obj_type=1, diameter=1, dn=mm.dn) # ## Create computational graph # In[ ]: ''' Assign Object (3D sample) to Class''' mm.obj_init = tf_go.generateInitObject(obj) ''' Create computational graph''' mm.create_graph(obj, if_xla=0) # ## Now evaluate the result - start inference # In[ ]: '''Compute result'''