def poop(): global sources meas_focus = get_measurements(sources=sources, mode='circular', psfs=psfs_focus, real=True) meas_mid = get_measurements(sources=sources, mode='circular', psfs=psfs_mid, real=True) meas_outer = get_measurements(sources=sources, mode='circular', psfs=psfs_outer, real=True) meas_csbs = get_measurements(sources=sources, mode='circular', psfs=psfs_csbs, real=True) meas_focus = add_noise(meas_focus, model='gaussian', dbsnr=15) meas_mid = add_noise(meas_mid, model='gaussian', dbsnr=15) meas_outer = add_noise(meas_outer, model='gaussian', dbsnr=15) meas_csbs = add_noise(meas_csbs, model='gaussian', dbsnr=15) # meas_focus = add_noise(meas_focus, model='poisson', max_count=20) # meas_mid = add_noise(meas_mid, model='poisson', max_count=20) # meas_outer = add_noise(meas_outer, model='poisson', max_count=20) # meas_csbs = add_noise(meas_csbs, model='poisson', max_count=20) recon_focus = tikhonov(psfs=psfs_focus, measurements=meas_focus, tikhonov_lam=1e-3) recon_mid = tikhonov(psfs=psfs_mid, measurements=meas_mid, tikhonov_lam=1e-3) recon_outer = tikhonov(psfs=psfs_outer, measurements=meas_outer, tikhonov_lam=1e-3) recon_csbs = tikhonov(psfs=psfs_csbs, measurements=meas_csbs, tikhonov_lam=1e-3) recon_focus -= np.mean(recon_focus, axis=(1, 2))[:, np.newaxis, np.newaxis] recon_mid -= np.mean(recon_mid, axis=(1, 2))[:, np.newaxis, np.newaxis] recon_outer -= np.mean(recon_outer, axis=(1, 2))[:, np.newaxis, np.newaxis] recon_csbs -= np.mean(recon_csbs, axis=(1, 2))[:, np.newaxis, np.newaxis] sources_comp = sources - np.mean(sources, axis=(1, 2))[:, np.newaxis, np.newaxis] result_focus = np.sum(compare_ssim(sources_comp, recon_focus)) result_mid = np.sum(compare_ssim(sources_comp, recon_mid)) result_outer = np.sum(compare_ssim(sources_comp, recon_outer)) result_csbs = np.sum(compare_ssim(sources_comp, recon_csbs)) print('focused SSIM sum:', result_focus) print('middle SSIM sum:', result_mid) print('outer SSIM sum:', result_outer) print('csbs SSIM sum:', result_csbs) return [result_focus, result_mid, result_outer, result_csbs]
def measure_reconstruct(): noise = 15 # dB SNR meas_focus = get_measurements(sources=sources, mode='circular', psfs=psfs_focus, real=True) meas_csbs = get_measurements(sources=sources, mode='circular', psfs=psfs_csbs, real=True) meas_focus = add_noise(meas_focus, model='gaussian', dbsnr=noise) meas_csbs = add_noise(meas_csbs, model='gaussian', dbsnr=noise) recon_focus = tikhonov(psfs=psfs_focus, measurements=meas_focus, tikhonov_lam=1e-3) recon_csbs = tikhonov(psfs=psfs_csbs, measurements=meas_csbs, tikhonov_lam=1e-3) result_focus = np.sum(compare_ssim(sources, recon_focus)) result_csbs = np.sum(compare_ssim(sources, recon_csbs)) ratio = result_csbs / result_focus return dict(**locals())
def cost(tikhonov_lam_exp, csbs_lam_exp): # csbs_grid psfs.copies = np.repeat(12, 12) # csbs_focus # psfs.copies = np.repeat(12, 2) csbs(psfs, sse_cost, 12, lam=10**csbs_lam_exp, order=1) measured = get_measurements(psfs=psfs, sources=truth, real=True) measured_noisy = add_noise(measured, model='poisson', max_count=500) recon = tikhonov( sources=measured, psfs=psfs, measurements=measured_noisy, tikhonov_lam=10**tikhonov_lam_exp ) plt.imshow(recon[0]) plt.show() plt.pause(.05) return compare_ssim(truth[0], recon[0]) + compare_ssim(truth[1], recon[1])
def cost(lam_exp, time_step_exp): recon = ista(psfs=psfs, measurements=measured, lam=10**lam_exp, time_step=10**time_step_exp, iterations=100)[0] cost = compare_ssim(truth[0], recon) plt.subplot(1, 3, 3) plt.title('Reconstruction - SSIM {:.3f}'.format(cost)) plt.imshow(recon) plt.axis('off') plt.xlabel('lam_exp={:.3f}\ntime_step_exp={:.3f}') plt.show() plt.pause(.05) return cost if cost > 0 else 0
real=True) meas_csbs = get_measurements(sources=sources, mode='circular', psfs=psfs_csbs, real=True) meas_focus = add_noise(meas_focus, model='gaussian', dbsnr=noise) meas_csbs = add_noise(meas_csbs, model='gaussian', dbsnr=noise) recon_focus = tikhonov(psfs=psfs_focus, measurements=meas_focus, tikhonov_lam=1e-3) recon_csbs = tikhonov(psfs=psfs_csbs, measurements=meas_csbs, tikhonov_lam=1e-3) result_focus = np.sum(compare_ssim(sources, recon_focus)) result_csbs = np.sum(compare_ssim(sources, recon_csbs)) print(result_csbs / result_focus, result_focus) # print('focused SSIM:', result_focus) # print('csbs SSIM:', result_csbs) # recon_focus_mean = recon_focus - np.mean(recon_focus, axis=(1, 2))[:, np.newaxis, np.newaxis] # recon_csbs_mean = recon_csbs - np.mean(recon_csbs, axis=(1, 2))[:, np.newaxis, np.newaxis] # sources_mean = sources - np.mean(sources, axis=(1, 2))[:, np.newaxis, np.newaxis] # result_focus_mean = np.sum(compare_ssim(sources_mean, recon_focus_mean)) # result_csbs_mean = np.sum(compare_ssim(sources_mean, recon_csbs_mean)) # print('focused SSIM, mean:', result_focus_mean)
def get_ssim(source, recon): return compare_ssim(recon, source)
dbsnr=15, model='Gaussian') measured_noisy_csbs = add_noise(measured_csbs, dbsnr=15, model='Gaussian') recon_focus = tikhonov(psfs=psfs_focus, measurements=measured_noisy_focus, tikhonov_lam=1e-3, tikhonov_order=order) recon_csbs = tikhonov(psfs=psfs_csbs, measurements=measured_noisy_csbs, tikhonov_lam=1e-3, tikhonov_order=order) psnr_focus.append(compare_psnr(sources, recon_focus)) psnr_csbs.append(compare_psnr(sources, recon_csbs)) ssim_focus.append(np.sum(compare_ssim(sources, recon_focus))) ssim_csbs.append(np.sum(compare_ssim(sources, recon_csbs))) print('psnr_focus:{} \npsnr_csbs:{} \nssim_focus:{} \nssim_csbs:{}'.format( np.array(psnr_focus).mean(), np.array(psnr_csbs).mean(), np.array(ssim_focus).mean(), np.array(ssim_csbs).mean())) plotter4d(recon_focus, title='recon_focus \n ssim:{} psnr:{}'.format( np.array(ssim_focus).mean(), np.array(psnr_focus).mean()), colorbar=True) plotter4d(recon_csbs, title='recon_csbs \n ssim:{} psnr:{}'.format(