def dpc_integration(dpc01, dpc10, pixelsize, idx4crop=[0, -1, 0, -1], plotErrorIntegration=False, saveFileSuf=None, shifthalfpixel=False, method='FC'): ''' TODO: Write Docstring Integration of DPC to obtain phase. Currently only supports Frankot Chellappa ''' if idx4crop == '': vmin = wpu.mean_plus_n_sigma(dpc01**2 + dpc10**2, -3) vmax = wpu.mean_plus_n_sigma(dpc01**2 + dpc10**2, 3) _, idx = wpu.crop_graphic_image(dpc01**2 + dpc10**2, kargs4graph={ 'cmap': 'viridis', 'vmin': vmin, 'vmax': vmax }) else: idx = idx4crop dpc01 = wpu.crop_matrix_at_indexes(dpc01, idx) dpc10 = wpu.crop_matrix_at_indexes(dpc10, idx) if method == 'FC': phase = wps.frankotchellappa(dpc01 * pixelsize[1], dpc10 * pixelsize[0], reflec_pad=True) phase = np.real(phase) else: wpu.print_red('ERROR: Unknown integration method: ' + method) if plotErrorIntegration: wps.error_integration(dpc01 * pixelsize[1], dpc10 * pixelsize[0], phase, pixelsize, errors=False, shifthalfpixel=shifthalfpixel, plot_flag=True) if saveFileSuf is not None: wpu.save_figs_with_idx(saveFileSuf) return phase
def dpc_integration(dpc01, dpc10, pixelsize, idx4crop=[0, -1, 0, -1], plotErrorIntegration=False, saveFileSuf=None, shifthalfpixel=False, method='FC'): ''' TODO: Write Docstring Integration of DPC to obtain phase. Currently only supports Frankot Chellappa ''' if idx4crop == '': vmin = wpu.mean_plus_n_sigma(dpc01**2+dpc10**2, -3) vmax = wpu.mean_plus_n_sigma(dpc01**2+dpc10**2, 3) _, idx = wpu.crop_graphic_image(dpc01**2+dpc10**2, kargs4graph={'cmap': 'viridis', 'vmin': vmin, 'vmax': vmax}) else: idx = idx4crop dpc01 = wpu.crop_matrix_at_indexes(dpc01, idx) dpc10 = wpu.crop_matrix_at_indexes(dpc10, idx) if method == 'FC': phase = wps.frankotchellappa(dpc01*pixelsize[1], dpc10*pixelsize[0], reflec_pad=True) phase = np.real(phase) else: wpu.print_red('ERROR: Unknown integration method: ' + method) if plotErrorIntegration: wps.error_integration(dpc01*pixelsize[1], dpc10*pixelsize[0], phase, pixelsize, errors=False, shifthalfpixel=shifthalfpixel, plot_flag=True) if saveFileSuf is not None: wpu.save_figs_with_idx(saveFileSuf) return phase
harmonicPeriod=harmPeriod, plotFlag=True, unwrapFlag=True, verbose=True) # the spatial resolution is the grating period, what we call the virtual pixel size virtual_pixelsize = [pixelsize[0]*img.shape[0]/int00.shape[0], pixelsize[1]*img.shape[1]/int00.shape[1]] # covert phaseFFT to physical quantities, ie, differential phase diffPhase01 = -alpha_x*virtual_pixelsize[1]/distDet2sample/wavelength diffPhase10 = -alpha_y*virtual_pixelsize[0]/distDet2sample/wavelength phase = wps.frankotchellappa(diffPhase01*pixelsize[1], diffPhase10*pixelsize[0]) phase = np.real(phase) # %% Plots saveFigFlag = True saveFileSuf = 'results' wgi.plot_intensities_harms(int00, int01, int10, virtual_pixelsize, saveFigFlag=saveFigFlag, titleStr='Intensity', saveFileSuf=saveFileSuf) wgi.plot_dark_field(darkField01, darkField10, virtual_pixelsize, saveFigFlag=saveFigFlag,
# ============================================================================= size = np.shape(dpc_x) pixelsize = .650*1e-6 xx, yy = wpu.realcoordmatrix(size[1], pixelsize, size[0], pixelsize) #============================================================================== # %% Integration #============================================================================== from wavepy.surface_from_grad import frankotchellappa, error_integration result = frankotchellappa(dpc_x, dpc_y, reflec_pad=True) result = np.real(result) result *= -1 result -= np.min(result) np.savetxt(fname_dpc_h5[:-3] + 'FC_integration.dat', result) #============================================================================== # %% Plot integrated 2d #============================================================================== wpu.plot_profile(xx[::5, ::5]*1e6, yy[::5, ::5]*1e6, result[::-5, ::-5])
totalS = np.sqrt(sx**2 + sy**2) # Differenctial Phase dpx = kwave * np.arctan2(sx * pixelsizeDetector, distDet2sample) dpy = kwave * np.arctan2(sy * pixelsizeDetector, distDet2sample) # Differenctial Thickness dTx = 1.0 / delta * np.arctan2(sx * pixelsizeDetector, distDet2sample) dTy = 1.0 / delta * np.arctan2(sy * pixelsizeDetector, distDet2sample) #============================================================================== # %% integration frankotchellappa #============================================================================== #integration_res = frankotchellappa(dTx,dTy) integration_res = wpsg.frankotchellappa(dTx * pixelsizeImg, dTy * pixelsizeImg) thickness = np.real(integration_res) thickness = thickness - np.min(thickness) # %% wpsg.error_integration(dTx * pixelsizeImg, dTy * pixelsizeImg, thickness, pixelsizeImg, shifthalfpixel=True, plot_flag=True) #==============================================================================
if noise is True: del_func_2d_x += .01*(2*np.random.rand(size[0],size[1]) -1) del_func_2d_y += .01*(2*np.random.rand(size[0],size[1]) -1) #============================================================================== # %% Integration #============================================================================== from wavepy.surface_from_grad import frankotchellappa, error_integration result = frankotchellappa(del_func_2d_x, del_func_2d_y, reflec_pad=True) integrated_2d_mod = np.abs(result) integrated_2d_r = np.real(result) integrated_2d_i = np.imag(result) integrated_2d = integrated_2d_r xx, yy = wpu.realcoordmatrix(func.shape[1], pixelsize, func.shape[0], pixelsize) #============================================================================== # %% Plot derivatives #==============================================================================
harmonicPeriod=harmPeriod, plotFlag=True, unwrapFlag=True, verbose=True) # the spatial resolution is the grating period, what we call the virtual pixel size virtual_pixelsize = [ pixelsize[0] * img.shape[0] / int00.shape[0], pixelsize[1] * img.shape[1] / int00.shape[1] ] # covert phaseFFT to physical quantities, ie, differential phase diffPhase01 = -alpha_x * virtual_pixelsize[1] / distDet2sample / wavelength diffPhase10 = -alpha_y * virtual_pixelsize[0] / distDet2sample / wavelength phase = wps.frankotchellappa(diffPhase01 * pixelsize[1], diffPhase10 * pixelsize[0]) phase = np.real(phase) # %% Plots saveFigFlag = True saveFileSuf = 'results' wgi.plot_intensities_harms(int00, int01, int10, virtual_pixelsize, saveFigFlag=saveFigFlag, titleStr='Intensity', saveFileSuf=saveFileSuf)
#plt.xlabel('[um]') #plt.ylabel('[um]') # #plt.show() #wpu.save_figs_with_idx(foutname) # #============================================================================== # %% integration frankotchellappa #============================================================================== #integration_res = frankotchellappa(dTx,dTy) integration_res = wpsg.frankotchellappa(dTx*pixelsizeImg, dTy*pixelsizeImg) thickness = np.real(integration_res) thickness = thickness - np.min(thickness) # %% wpsg.error_integration(dTx*pixelsizeImg, dTy*pixelsizeImg, thickness, [pixelsizeImg, pixelsizeImg], shifthalfpixel=True, plot_flag=True) #============================================================================== # %% Thickness #==============================================================================