コード例 #1
0
def save_parameters_config(holo, center, prop_dist, phase, roi, folder, image_numbers, bs_diam, propagate=False):
    '''
    old function to save parameters in a config file and reconstruction as numpy array. Replaced by saving everything in a hdf file with save_parameters()
    
    reconstruct the shifted and masked hologram (propagation and phase shift are performed here.)
    save all parameters in numpy-files (holo and beamstop) and a config file (rest)
    if the folder you put in does not exist, it will be created.
    '''
    image_numbers = np.array(image_numbers)
    if not(os.path.exists(folder)):
        print("Creating folder " + folder)
        os.mkdir(folder)

    if propagate:
        recon = fth.reconstruct(fth.propagate(holo, prop_dist*1e-6)*np.exp(1j*phase))
    else:
        recon = fth.reconstruct(holo*np.exp(1j*phase))
    print('Shifted phase by %f.'%phase)
    
    if image_numbers.size == 1:
        im = image_numbers
    elif np.isnan(image_numbers[0]):
        im = image_numbers[1]
    else:
        im = image_numbers[0]

    np.save(folder + '%i_recon'%im, recon[roi[2]:roi[3], roi[0]:roi[1]])
    
    fth.save_config(image_numbers, center, bs_diam, prop_dist, phase, roi, folder + '%i_config.ini'%im)
    return
コード例 #2
0
ファイル: holo_sim.py プロジェクト: riccbatt/FTH_RB
def autophase_similar2(reco, reco_original, o_mask, guess=0):
    '''find phase such that reco and reco_original are as similar as possible. Searches around guess +/- 0.5'''
    #f = lambda phase : phaserot(reco,phase).imag.std()/phaserot(reco,phase).real.std()
    f = lambda phase: np.sum(
        np.real((fth.reconstruct(phaserot(reco, phase)) - fth.reconstruct(
            reco_original)) * o_mask)**2)
    phase_guess = np.linspace(guess - 3.14, guess + 3.14, 40)
    error = np.array([f(phase) for phase in phase_guess])
    try:
        phase = least_squares(f, phase_guess[error.argmin()])
        return phase.x[0]
    except:
        return phase_guess[error.argmin()]
コード例 #3
0
def set_roi(holo, scale = (1,99)):
    """ 
    Select a ROI somewhat interactively, not used anymore!
    Input the shfited and masked hologram as returned from recon_allNew.
    Returns the four input fields. When you are finished, you can save the positions of the fields.
    -------
    author: KG 2019
    """
    recon=fth.reconstruct(holo)
    
    mi, ma = np.percentile(np.real(recon), scale)
    fig, ax = plt.subplots()
    ax = plt.imshow(np.real(recon), cmap='gray', vmin=mi, vmax=ma)
    plt.colorbar()

    style = {'description_width': 'initial'}

    ROIx1 = widgets.IntText(value=None, description='ROI x1 coordinate:', disabled=False, style=style)
    ROIx2 = widgets.IntText(value=None, description='ROI x2 coordinate:', disabled=False, style=style)
    ROIy1 = widgets.IntText(value=None, description='ROI y1 coordinate:', disabled=False, style=style)
    ROIy2 = widgets.IntText(value=None, description='ROI y2 coordinate:', disabled=False, style=style)

    button = widgets.Button(description='Finished')
    display(ROIx1, ROIx2, ROIy1, ROIy2, button)

    return (ROIx1, ROIx2, ROIy1, ROIy2, button)
コード例 #4
0
    def p(x, y):
        image = fth.reconstruct(
            fth.propagate(holo,
                          x * 1e-6,
                          ccd_dist=ccd_dist,
                          energy=energy,
                          px_size=px_size) * np.exp(1j * y))
        mir, mar = np.percentile(np.real(image[ROI[2]:ROI[3], ROI[0]:ROI[1]]),
                                 scale)
        mii, mai = np.percentile(np.imag(image[ROI[2]:ROI[3], ROI[0]:ROI[1]]),
                                 scale)

        ax1 = axs[0].imshow(np.real(image[ROI[2]:ROI[3], ROI[0]:ROI[1]]),
                            cmap='gray',
                            vmin=mir,
                            vmax=mar)
        #fig.colorbar(ax1, ax=axs[0], fraction=0.046, pad=0.04)
        axs[0].set_title("Real Part")
        ax2 = axs[1].imshow(np.imag(image[ROI[2]:ROI[3], ROI[0]:ROI[1]]),
                            cmap='gray',
                            vmin=mii,
                            vmax=mai)
        #fig.colorbar(ax2, ax=axs[1], fraction=0.046, pad=0.04)
        axs[1].set_title("Imaginary Part")
        fig.tight_layout()
        print('REAL: max=%i, min=%i' %
              (np.max(np.real(image)), np.min(np.real(image))))
        print('IMAG: max=%i, min=%i' %
              (np.max(np.imag(image)), np.min(np.imag(image))))
        return
コード例 #5
0
    def p(x, y, fx, fy):
        image = fth.reconstruct(fth.propagate(holo, x*1e-6, experimental_setup)*np.exp(1j*y))
        simage = fth.sub_pixel_centering(image, fx, fy)

        ax1 = axs[0].imshow(np.real(simage[roi[2]:roi[3], roi[0]:roi[1]]), cmap='gray')
        axs[0].set_title("Real Part")
        ax2 = axs[1].imshow(np.imag(simage[roi[2]:roi[3], roi[0]:roi[1]]), cmap='gray')
        axs[1].set_title("Imaginary Part")
        fig.tight_layout()
        print('REAL: max=%i, min=%i'%(np.max(np.real(simage)), np.min(np.real(simage))))
        print('IMAG: max=%i, min=%i'%(np.max(np.imag(simage)), np.min(np.imag(simage))))
        return
コード例 #6
0
 def p(x):
     image = fth.reconstruct(holo*np.exp(1j*x))
     ax1 = axs[0].imshow(np.real(image[roi[2]:roi[3], roi[0]:roi[1]]), cmap='gray')
     #fig.colorbar(ax1, ax=axs[0], fraction=0.046, pad=0.04)
     axs[0].set_title("Real Part")
     ax2 = axs[1].imshow(np.imag(image[roi[2]:roi[3], roi[0]:roi[1]]), cmap='gray')
     #fig.colorbar(ax2, ax=axs[1], fraction=0.046, pad=0.04)
     axs[1].set_title("Imaginary Part")
     fig.tight_layout()
     print('REAL: max=%i, min=%i'%(np.max(np.real(image)), np.min(np.real(image))))
     print('IMAG: max=%i, min=%i'%(np.max(np.imag(image)), np.min(np.imag(image))))
     return
コード例 #7
0
    def p(x,y,phi):
        #create bessel function
        J=x*2*spec.j1(R*y*Q)/(R*y*Q)
        J[(npx//2),npy//2]=x
        #Wiener filtering
        J_w=(J**2+phi)/J
        image = fth.reconstruct(holo/J_w)
        mir, mar = np.percentile(np.real(image[ROI[2]:ROI[3], ROI[0]:ROI[1]]), scale)
        mii, mai = np.percentile(np.imag(image[ROI[2]:ROI[3], ROI[0]:ROI[1]]), scale)

        ax1 = axs[0].imshow(np.real(image[ROI[2]:ROI[3], ROI[0]:ROI[1]]), cmap='gray', vmin = mir, vmax = mar)
        #fig.colorbar(ax1, ax=axs[0], fraction=0.046, pad=0.04)
        axs[0].set_title("Real Part")
        ax2 = axs[1].imshow(np.imag(image[ROI[2]:ROI[3], ROI[0]:ROI[1]]), cmap='gray', vmin = mii, vmax = mai)
        #fig.colorbar(ax2, ax=axs[1], fraction=0.046, pad=0.04)
        axs[1].set_title("Imaginary Part")
        fig.tight_layout()
        print('REAL: max=%i, min=%i'%(np.max(np.real(image)), np.min(np.real(image))))
        print('IMAG: max=%i, min=%i'%(np.max(np.imag(image)), np.min(np.imag(image))))
        return