import NanoImagingPack as nip

# Optionally, tweak styles.
mpl.rc('figure', figsize=(8, 6))
mpl.rc('image', cmap='gray')

if (1):
    if (1):
        var_tvc = 1e-11
        var_tv = 1e-1
        experiments.regularizer = 'L1'
        #for var_tv in (1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e-0, 1e1, 1e2):
        #for var_tvc in (1e-10, 1e-8, 1e-6, 1e-4, 1e-2):
        np_meas_file = './Data/PHANTOM/HeLa_cell_mat_obj_100.mat'
        matname = 'HeLa_cell_mat'
        obj_real = data.import_realdata_h5(filename=np_meas_file,
                                           matname=matname)
        obj_absorption = obj_real * 0
        obj_guess = (obj_real + 1j * obj_absorption)
        #%%
        '''Define some stuff related to infrastructure'''
        mytimestamp = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
        basepath = ""
        is_aberration = False
        is_aberation_iterstart = 0  # When to start optimizing for aberration?
        is_padding = False
        is_optimization = True
        is_absorption = 0
        is_obj_init_tikhonov = False  # intialize the
        is_norm = False  # Want to have a floating value for the background?
        is_recomputemodel = True  # TODO: Make it automatic!
        is_estimatepsf = False
savepath = basepath + experiments.resultpath + mytimestamp + '_' + '_PSFmodel_' + psf_model + experiments.regularizer + '_' + str(
    experiments.lambda_reg) + '_eps_' + str(
        experiments.myepstvval) + '_' + 'Shift_x-' + str(
            experiments.shiftIcX) + 'Shift_y-' + str(experiments.shiftIcY)
tf_helper.mkdir(savepath)
print('My  path is: ' + savepath)
''' MODELLING StARTS HERE'''
if is_recomputemodel:
    tf.reset_default_graph()
    # need to figure out why this holds somehow true - at least produces reasonable results
    ''' 1.) Read in the parameters of the dataset '''
    if (experiments.obj_meas_filename.find('mat') == -1):
        obj_meas = np.load(experiments.obj_meas_filename)
    else:
        obj_meas = data.import_realdata_h5(
            filename=experiments.obj_meas_filename,
            matname=experiments.matlab_val_name,
            is_complex=True)

    # If Z-is odd numbered
    if (np.mod(obj_meas.shape[0], 2) == 1):
        obj_meas = obj_meas[0:obj_meas.shape[0] - 1, :, :]
    obj_meas = obj_meas[:, :, :, ]

    # Eventually add an imaginary background to synchronize to methods
    if (psf_model == 'BORN'):
        obj_meas = obj_meas + experiments.mybackgroundval
    ''' 2.) Read (optional) referecne object for PSF calibration '''
    if (is_estimatepsf
        ):  # if we know the object already, we only need to update the PSF
        obj_meas = data.import_realdata_h5(
            filename=experiments.matlab_obj_file,
Exemple #3
0
dn = .105 #(1.437-1.3326)#/np.pi
myfac = 1 #- 1e-6


#muscat.NAo = .95
#muscat.dz = 0.1625*2#muscat.lambda0/4
#muscat.dy = .2; muscat.dx = muscat.dy#muscat.lambda0/4
#muscat.dx = 0.1560#muscat.lambda0/4
#muscat.Nx = 50; muscat.Ny = 50; muscat.Nz = 50
#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):
    np.abs(zernikefactors) > 0
) * 1  #!= np.array((0, 0, 0, 0, 0, 0, , 1, 1, 1, 1))# mask which factors should be updated
'''START CODE'''
tf.reset_default_graph()  # just in case there was an open session

# Generate Test-Object
''' File which stores the experimental parameters from the Q-PHASE setup 
    1.) Read in the parameters of the dataset '''
matlab_pars = data.import_parameters_mat(filename=matlab_par_file,
                                         matname=matlab_par_name)
''' 2.) Read in the parameters of the dataset '''
if (matlab_val_file.find('mat') == -1):
    matlab_val = np.load(matlab_val_file)
else:
    matlab_val = data.import_realdata_h5(filename=matlab_val_file,
                                         matname=matlab_val_name,
                                         is_complex=True)

if (np.mod(matlab_val.shape[0], 2) == 1):
    matlab_val = matlab_val[0:matlab_val.shape[0] - 1, :, :]
#roisize=50
#roicenter = np.array((215,201))
#matlab_val = np.flip(matlab_val[0:100,roicenter[0]-roisize:roicenter[0]+roisize,roicenter[1]-roisize:roicenter[1]+roisize],0)
''' Create the Model'''
muscat = mus.MuScatModel(matlab_pars, is_optimization=is_optimization)
# Correct some values - just for the puprose of fitting in the RAM
muscat.Nx, muscat.Ny, muscat.Nz = matlab_val.shape[1], matlab_val.shape[
    2], matlab_val.shape[0]
muscat.shiftIcY = shiftIcY
muscat.shiftIcX = shiftIcX
muscat.dn = dn
Niter = 5000
Ndisplay = 10


'''START CODE'''
tf.reset_default_graph() # just in case there was an open session

''' File which stores the experimental parameters from the Q-PHASE setup 
    1.) Read in the parameters of the dataset ''' 
matlab_pars = data.import_parameters_mat(filename = matlab_par_file, matname='myParameterNew')

''' 2.) Read in the parameters of the dataset ''' 
if(matlab_val_file.find('mat')==-1):
    matlab_val = np.load(matlab_val_file)
else:
    matlab_val = data.import_realdata_h5(filename = matlab_val_file, matname='allAmp_red', is_complex=True)

if(is_flip):
    np_meas = np.flip(matlab_val,0)
    print('Attention: We are flipping the data!')
else:
    np_meas = matlab_val
print('do we need to flip the data?! -> Observe FFT!!')


''' 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
# need to figure out why this holds somehow true - at least produces reasonable results
'''START CODE'''
tf.reset_default_graph()  # just in case there was an open session

# Generate Test-Object
''' File which stores the experimental parameters from the Q-PHASE setup 
    1.) Read in the parameters of the dataset '''
matlab_pars = data.import_parameters_mat(filename=configs.matlab_par_file,
                                         matname=configs.matlab_par_name)
''' 2.) Read in the parameters of the dataset '''
if (configs.matlab_val_file.find('mat') == -1):
    matlab_val = np.load(configs.matlab_val_file)
else:
    matlab_val = data.import_realdata_h5(filename=configs.matlab_val_file,
                                         matname=configs.matlab_val_name,
                                         is_complex=True)

if (np.mod(matlab_val.shape[0], 2) == 1):
    matlab_val = matlab_val[0:matlab_val.shape[0] - 1, :, :]

matlab_val = matlab_val + configs.mybackgroundval
#roisize=50
#roicenter = np.array((215,201))
#matlab_val = np.flip(matlab_val,0 )#[0:100,roicenter[0]-roisize:roicenter[0]+roisize,roicenter[1]-roisize:roicenter[1]+roisize],0)
''' Create the Model'''
muscat = mus.MuScatModel(matlab_pars, is_optimization=configs.is_display)

# Correct some values - just for the puprose of fitting in the RAM
muscat.Nx, muscat.Ny, muscat.Nz = matlab_val.shape[1], matlab_val.shape[
    2], matlab_val.shape[0]

#tf.reset_default_graph()

''' File which stores the experimental parameters from the Q-PHASE setup 
    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)

except (FileExistsError):
    print('Folder exists already')

#%% optimize over the hyperparameters
for i_epoch in range(Nepoch):
    for i_file in range(len(my_meas_files)):
        mylambdatv = lambda_tv
        myepstvval = eps_tv
        #    for eps_tv in eps_tv:
        print('Evtl unwrap it!')
        # this is the initial guess of the reconstruction
        ''' 2.) Read in the parameters of the dataset '''
        print('Now feeding file: ' + my_meas_files[i_file])
        print('Now feeding file: ' + my_gt_files[i_file])
        np_meas = data.import_realdata_h5(filename=my_meas_files[i_file],
                                          matname='allAmp_red',
                                          is_complex=True)
        np_obj = data.import_realdata_h5(filename=my_gt_files[i_file],
                                         matname='mysphere',
                                         is_complex=False)
        ''' Create a 3D Refractive Index Distributaton as a artificial sample'''
        obj = np_obj * dn
        obj_absorption = np_obj * .001
        obj = obj + 1j * obj_absorption
        init_guess = obj

        if (False):
            # This won't make much sense here!
            # run the fwd model once
            '''Numpy to Tensorflow'''
            my_fwd = sess.run(tf_fwd)