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
phase = wgi.dpc_integration(diffPhase01, diffPhase10, virtual_pixelsize) #phase = np.real(phase) delta = 5.3276849026895334e-06 wgi.plot_integration(-(phase - np.min(phase))/kwave/delta*1e6, virtual_pixelsize, titleStr=r'Thickness Beryllium $[\mu m]$,' +'\n Frankot Chellappa integration', plot3dFlag=True, saveFigFlag=True, saveFileSuf=saveFileSuf) wps.error_integration(diffPhase01*virtual_pixelsize[1], diffPhase10*virtual_pixelsize[0], phase, virtual_pixelsize, errors=False, plot_flag=True) wpu.save_figs_with_idx(saveFileSuf) # %% def _pad_2_make_square(array, mode='edge'): diff_shape = array.shape[0] - array.shape[1] if diff_shape > 1: return np.pad(array, ((0, 0), (0, diff_shape)), mode=mode) elif diff_shape < 1: return np.pad(array, ((0, -diff_shape), (0, 0)), mode=mode)
#============================================================================== # %% 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) #============================================================================== # %% Plot #============================================================================== def mySaveFig(figname=None): if figname is None: figname = str('output/graph_{0:02d}.png'.format(next(figCount))) plt.savefig(figname) print(figname + ' SAVED')
plt.plot(yy[:,midleY], func[:,midleY], '-kx', markersize=10, label='f y') shifted = integrated_2d[:,midleY] + np.mean(func[:,midleY]-integrated_2d[:,midleY]) plt.plot(yy[:,midleY]-pixelsize/2, shifted, '-ro', label='intemidleXgrated shifted f y') plt.xlabel(r'$y$') plt.legend() plt.title(r'Profile $y$') plt.show(block=True) # %% Plot Integration Qaulity errorx, errory = error_integration(del_func_2d_x, del_func_2d_y, integrated_2d, pixelsize, plot_flag=True) # %% #exit() # %% foo = del_func_2d_y[midleX,:] plt.figure() plt.plot(xx[midleX,:], foo, '-kx', markersize=10) plt.plot(xx[midleX,:]+pixelsize/2, wpu.shift_subpixel_1d(foo, 2), '-r.', markersize=10) plt.plot(xx[midleX,:]+pixelsize/4, wpu.shift_subpixel_1d(foo, 4), '-b.', markersize=10)
#phase = np.real(phase) delta, _ = wpu.get_delta(phenergy, choice_idx=1, gui_mode=False) wgi.plot_integration(-(phase - np.min(phase)) / kwave / delta * 1e6, virtual_pixelsize, titleStr=r'Thickness Beryllium $[\mu m]$,' + '\n Frankot Chellappa integration', plot3dFlag=True, saveFigFlag=True, saveFileSuf=saveFileSuf) wps.error_integration(diffPhase01 * virtual_pixelsize[1], diffPhase10 * virtual_pixelsize[0], phase, virtual_pixelsize, errors=False, plot_flag=True) wpu.save_figs_with_idx(saveFileSuf) # %% def _pad_2_make_square(array, mode='edge'): diff_shape = array.shape[0] - array.shape[1] if diff_shape > 1: return np.pad(array, ((0, 0), (0, diff_shape)), mode=mode)
#============================================================================== # %% 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 #============================================================================== stride = 1 wpu.plot_profile(xmatrix[::stride, ::stride]*1e6, ymatrix[::stride, ::stride]*1e6, thickness[::stride, ::stride]*1e6, title='Thickness', xlabel='[um]', ylabel='[um]', arg4main={'cmap':'spectral'}) #, xo=0.0, yo=0.0)_1Dparabol_4_fit plt.show(block=True)