# Load images [H1, H2] = load_pyobject(folder + H_filename) [S1, S2] = load_pyobject(folder + S_filename) [D1, D2] = load_pyobject(folder + D_filename) # Rescale H1.rescale(), H2.rescale() S1.rescale(), S2.rescale() D1.rescale(), D2.rescale() # Maximum intensity of the image and standard deviation # of the noise if r == 0: I_max_r0 = max([ np.abs(ktoi(D1.k)[..., 0, 0]).max(), np.abs(ktoi(D1.k)[..., 1, 0]).max() ]) for n, nlevel in enumerate(noise_levels): # Standard deviation of the noise std = nlevel * I_max_r0 # Generate noise in the image domain noise_1 = np.random.normal(0, std, D1.k.shape) \ + 1j*np.random.normal(0, std, D1.k.shape) noise_2 = np.random.normal(0, std, D2.k.shape) \ + 1j*np.random.normal(0, std, D2.k.shape) # Noise in the fourier domain
[I1, mask] = load_pyobject(folder + filename) I2 = -1 else: [I1, I2, mask] = load_pyobject(folder + filename) # Export matlab object I = {'I1': I1, 'I2': I2, 'M': mask} savemat('inputs/3D_experiments/' + fname + '.mat', {'I': I}) elif folder is not 'inputs/masks/': # Load kspaces and rescale if if_exact(fname): K1 = load_pyobject(folder + filename) K1.rescale() I = ktoi(K1.k) else: [K1, K2] = load_pyobject(folder + filename) K1.rescale() K2.rescale() I = ktoi(K1.k - K2.k) # Scale image I = scale_image(I, mag=False, real=True, compl=True) # Export matlab object savemat('inputs/noise_free_images/' + fname + '.mat', {'I': I}) else: # Load mask
elif trajectory == 'spiral': traj = Spiral(FOV=FOV, res=res, oversampling=2, lines_per_shot=2, interleaves=10) # traj.plot_trajectory() # Non-cartesian kspace K = TrajToImage(traj.points, 1000.0 * traj.times, Mxy, r, 50.0) # Non-uniform fft x0 = traj.points[0].flatten().reshape((-1, 1)) x1 = traj.points[1].flatten().reshape((-1, 1)) x0 *= res[0] // 2 / x0.max() x1 *= res[1] // 2 / x1.max() dcf = (x0**2 + x1**2)**0.5 # density compensation function kxky = np.concatenate((x0, x1), axis=1) # flattened kspace coordinates y = K.flatten().reshape((-1, 1)) # flattened kspace measures image = nufft_adjoint(y * dcf, kxky, res) # inverse nufft # Show results fig, axs = plt.subplots(2, 3, figsize=(10, 10)) axs[0, 0].imshow(np.abs(K_c[::2, :])) axs[0, 1].imshow(np.abs(ktoi(K_c[::2, :]))) axs[0, 2].imshow(np.angle(ktoi(K_c[::2, :]))) axs[1, 0].imshow(np.abs(itok(image))) axs[1, 1].imshow(np.abs(image)) axs[1, 2].imshow(np.angle(image)) plt.show()
def to_img(self): return ktoi(self.k)