def image_formation(): Ncopy = 1000 use_sPCA = False image_idx = 0 SNR = .1 r_max = 64 seed = 0 Coeff, Freqs, rad_freqs, Mean, Phi_ns, sigma, Coeff_raw, rotations = make_data( Ncopy=Ncopy, SNR=SNR, seed=seed, image_idx=image_idx, sPCA=use_sPCA) image0 = recover_image(Coeff_raw, Phi_ns, Freqs, r_max, Mean) Rl = np.expand_dims(np.exp(1j * 2 * np.pi * 45 / 360 * Freqs), axis=-1) Coeff_rotated = Coeff_raw * Rl image_rotated = recover_image(Coeff_rotated, Phi_ns, Freqs, r_max, Mean) image_rotated_noisy = recover_image(np.expand_dims(Coeff[:, 0], axis=-1), Phi_ns, Freqs, r_max, Mean) plt.subplot(131) plt.imshow(image0, cmap='gray') plt.axis('off') plt.subplot(132) plt.imshow(image_rotated, cmap='gray') plt.axis('off') plt.subplot(133) plt.imshow(image_rotated_noisy, cmap='gray') plt.axis('off') plt.savefig('mra_2d_observations_model.png') plt.savefig('mra_2d_observations_model.eps') plt.clf()
def ppm_em_experiment(seed, image_idx, SNR, Ncopy, Ndir, use_sPCA, use_signal_prior, gamma, BW, path_learning, P): Coeff, Freqs, rad_freqs, Mean, Phi_ns, sigma, Coeff_raw, rotations = make_data( Ncopy=Ncopy, SNR=SNR, seed=seed, image_idx=image_idx, sPCA=use_sPCA) image0 = recover_image(Coeff_raw, Phi_ns, Freqs, r_max, Mean) TT = time() Coeff_s, est_rotations = synchronize_2d(Coeff, Freqs, Ndir) t_synch = time() - TT x_s = np.expand_dims(np.mean(Coeff_s, axis=-1), axis=-1) x = align_image(x_s, Coeff_raw, Freqs) imager = recover_image(x, Phi_ns, Freqs, r_max, Mean) err_synch = np.sqrt( np.sum(np.sum((image0 - imager)**2, axis=-1), axis=0) / np.sum(np.sum(image0**2, axis=-1), axis=0)) x, num_iter_synch_em, t_synch_em = EM_General_Prior(Coeff, Freqs, sigma, Ndir, 1 / Ndir * np.ones( (Ndir, 1)), Ndir, 0, Coeff_raw, use_signal_prior, uniform=False) x = align_image(x, Coeff_raw, Freqs) imager = recover_image(x, Phi_ns, Freqs, r_max, Mean) err_synch_em = np.sqrt( np.sum(np.sum((image0 - imager)**2, axis=-1), axis=0) / np.sum(np.sum(image0**2, axis=-1), axis=0)) results = pd.DataFrame() results = results.append( { 'use_signal_prior': use_signal_prior, 'use_sPCA': use_sPCA, 'seed': seed, 'SNR': SNR, 'sigma': sigma, 'N': Ncopy, 'L': Coeff.shape[0], 'image_idx': image_idx, 'err': err_synch_em, 'num_iter': num_iter_synch_em, 'BW': BW, 'gamma': gamma, 't': t_synch + t_synch_em, 't_synch': t_synch, 't_em': t_synch_em, 'err_synch': err_synch }, ignore_index=True) return results
def draw_from_prior(): Ncopy = 10000 use_sPCA = True image_idx = 0 SNR = 10 filename = 'E70s.mat' r_max = 64 seed = 0 Coeff, Freqs, rad_freqs, Mean, Phi_ns, sigma, Coeff_raw, rotations = make_data( Ncopy=Ncopy, SNR=SNR, seed=seed, image_idx=image_idx, sPCA=use_sPCA) data_prior = np.expand_dims(4 * np.exp(-np.asarray(Freqs) / 8), axis=-1) Gamma_a = np.diag(np.abs(data_prior[:, 0])**2) np.random.seed(10) for i in range(9): x = 1 / np.sqrt(2) * ( np.random.multivariate_normal(np.zeros( (Freqs.shape[0], )), Gamma_a) + 1j * np.random.multivariate_normal(np.zeros( (Freqs.shape[0], )), Gamma_a)) Coeff_raw = np.expand_dims(x, axis=-1) image0 = recover_image(Coeff_raw, Phi_ns, Freqs, r_max, Mean) plt.subplot('33%d' % (i + 1)) plt.imshow(image0, cmap='gray') plt.axis('off') plt.savefig('draw_from_prior.png') plt.savefig('draw_from_prior.eps') plt.clf()
def synchronize_and_match_experiment(seed, image_idx, SNR, Ncopy, Ndir, use_sPCA, P): Coeff, Freqs, rad_freqs, Mean, Phi_ns, sigma, Coeff_raw, rotations = make_data( Ncopy=Ncopy, SNR=SNR, seed=seed, image_idx=image_idx, sPCA=use_sPCA) image0 = recover_image(Coeff_raw, Phi_ns, Freqs, r_max, Mean) TT = time() Coeff_s, est_rotations = synchronize_and_match_2d(Coeff, Freqs, P=P, L=Ndir) t_synch = time() - TT h, bin_edges = np.histogram((est_rotations - rotations) % 360, bins=np.arange(-0.5, 360 + 0.5)) measured_rho = np.expand_dims(h / np.sum(h), axis=-1) x_s = np.expand_dims(np.mean(Coeff_s, axis=-1), axis=-1) x = align_image(x_s, Coeff_raw, Freqs) imager = recover_image(x, Phi_ns, Freqs, r_max, Mean) err_synch = np.sqrt( np.sum(np.sum((image0 - imager)**2, axis=-1), axis=0) / np.sum(np.sum(image0**2, axis=-1), axis=0)) print('#### synchronize and match ####') print('e = %f' % err_synch) results = pd.DataFrame() results = results.append( { 'use_sPCA': use_sPCA, 'seed': seed, 'SNR': SNR, 'sigma': sigma, 'N': Ncopy, 'L': Coeff.shape[0], 'image_idx': image_idx, 'rho': measured_rho, 'err': err_synch, 'num_iter': 0, 't': t_synch }, ignore_index=True) return results
def known_rotations_experiment(seed, image_idx, SNR, Ncopy, Ndir, use_sPCA): Coeff, Freqs, rad_freqs, Mean, Phi_ns, sigma, Coeff_raw, rotations = make_data( Ncopy=Ncopy, SNR=SNR, seed=seed, image_idx=image_idx, sPCA=use_sPCA) image0 = recover_image(Coeff_raw, Phi_ns, Freqs, r_max, Mean) est_rotations = rotations Coeff_s = np.zeros_like(Coeff) for i in range(Ncopy): Coeff_s[:, i] = Coeff[:, i] * np.exp( -1j * 2 * np.pi * est_rotations[i] / 360 * Freqs) t_synch = 0 h, bin_edges = np.histogram((est_rotations - rotations) % 360, bins=np.arange(-0.5, 360 + 0.5)) measured_rho = np.expand_dims(h / np.sum(h), axis=-1) x_s = np.expand_dims(np.mean(Coeff_s, axis=-1), axis=-1) x = align_image(x_s, Coeff_raw, Freqs) imager = recover_image(x, Phi_ns, Freqs, r_max, Mean) err_synch = np.sqrt( np.sum(np.sum((image0 - imager)**2, axis=-1), axis=0) / np.sum(np.sum(image0**2, axis=-1), axis=0)) print('#### oracle ####') print('e = %f' % err_synch) results = pd.DataFrame() results = results.append( { 'use_sPCA': use_sPCA, 'seed': seed, 'SNR': SNR, 'sigma': sigma, 'N': Ncopy, 'L': Coeff.shape[0], 'image_idx': image_idx, 'rho': measured_rho, 'err': err_synch, 'num_iter': 0, 't': t_synch }, ignore_index=True) return results
def standard_em_experiment(seed, image_idx, SNR, Ncopy, Ndir, use_sPCA, use_signal_prior): Coeff, Freqs, rad_freqs, Mean, Phi_ns, sigma, Coeff_raw, rotations = make_data( Ncopy=Ncopy, SNR=SNR, seed=seed, image_idx=image_idx, sPCA=use_sPCA) image0 = recover_image(Coeff_raw, Phi_ns, Freqs, r_max, Mean) x, num_iter_em_uniform, t_em_uniform = EM_General_Prior(Coeff, Freqs, sigma, Ndir, 1 / Ndir * np.ones( (Ndir, 1)), Ndir, 0, Coeff_raw, use_signal_prior, uniform=True) x = align_image(x, Coeff_raw, Freqs) imager = recover_image(x, Phi_ns, Freqs, r_max, Mean) err_em_uniform = np.sqrt( np.sum(np.sum((image0 - imager)**2, axis=-1), axis=0) / np.sum(np.sum(image0**2, axis=-1), axis=0)) results = pd.DataFrame() results = results.append( { 'use_signal_prior': use_signal_prior, 'use_sPCA': use_sPCA, 'seed': seed, 'SNR': SNR, 'sigma': sigma, 'N': Ncopy, 'L': Coeff.shape[0], 'image_idx': image_idx, 'err': err_em_uniform, 'num_iter': num_iter_em_uniform, 't': t_em_uniform }, ignore_index=True) return results