## Create and add in Rician noise noiseR = np.random.random(E.shape) noiseI = np.random.random(E.shape) noise = noiseR + 1j * noiseI tau = (10.0**(-sig_noise / 10.0) * norm(E, 2)) noise = noise * (tau / norm(noise)) # Normalize to get desired SNR E = E + noise # Add noise to signal E = abs(E) # Measured amplitude signal # Drop data np.random.shuffle(mask) E[mask] = np.nan fit = sk.fit(E) xyz = fit.directions if len(xyz) > 1: w = np.dot(xyz[0], xyz[1]) else: w = 1 recovered_angle[n, kk] = np.rad2deg(np.arccos(np.abs(w))) # End MC simulation np.savetxt('_recovered_angle.npy', recovered_angle) np.set_printoptions(precision=2, suppress=True)
""" Remove most of the background using dipy's mask module. """ # Instantiate model from dipy.reconst.multi_voxel import multi_voxel_fit SparseKernelModel.fit = multi_voxel_fit(SparseKernelModel.fit) #from dipy.segment.mask import median_otsu #maskdata, mask = median_otsu(data, 3, 1, True, # vol_idx=range(10, 50), dilate=2) # Select segment of data to work with data_small = data[13:43, 44:74, 28:29] fit = model.fit(data_small) sphere = get_sphere('symmetric724') odfs = fit.odf(sphere) # It is common for some models to produce negative values, we can remove those # using ``np.clip`` odfs = np.clip(odfs, 0, np.max(odfs, -1)[..., None]) # Visualie from dipy.viz import fvtk r = fvtk.ren() fvtk.add(r, fvtk.sphere_funcs(odfs, sphere, colormap='jet')) fn = model.__class__.__name__ + '_odfs.png'