def test_odf_sh_to_sharp(): SNR = None S0 = 1 _, fbvals, fbvecs = get_fnames('small_64D') bvals, bvecs = read_bvals_bvecs(fbvals, fbvecs) gtab = gradient_table(bvals, bvecs) mevals = np.array(([0.0015, 0.0003, 0.0003], [0.0015, 0.0003, 0.0003])) S, _ = multi_tensor(gtab, mevals, S0, angles=[(10, 0), (100, 0)], fractions=[50, 50], snr=SNR) sphere = default_sphere with warnings.catch_warnings(): warnings.filterwarnings("ignore", message=descoteaux07_legacy_msg, category=PendingDeprecationWarning) qb = QballModel(gtab, sh_order=8, assume_normed=True) qbfit = qb.fit(S) with warnings.catch_warnings(): warnings.filterwarnings("ignore", message=descoteaux07_legacy_msg, category=PendingDeprecationWarning) odf_gt = qbfit.odf(sphere) Z = np.linalg.norm(odf_gt) odfs_gt = np.zeros((3, 1, 1, odf_gt.shape[0])) odfs_gt[:, :, :] = odf_gt[:] with warnings.catch_warnings(): warnings.filterwarnings("ignore", message=descoteaux07_legacy_msg, category=PendingDeprecationWarning) odfs_sh = sf_to_sh(odfs_gt, sphere, sh_order=8, basis_type=None) odfs_sh /= Z with warnings.catch_warnings(): warnings.filterwarnings("ignore", message=descoteaux07_legacy_msg, category=PendingDeprecationWarning) fodf_sh = odf_sh_to_sharp(odfs_sh, sphere, basis=None, ratio=3 / 15., sh_order=8, lambda_=1., tau=0.1) fodf = sh_to_sf(fodf_sh, sphere, sh_order=8, basis_type=None) directions2, _, _ = peak_directions(fodf[0, 0, 0], sphere) assert_equal(directions2.shape[0], 2)
def test_odf_sh_to_sharp(): SNR = 100 S0 = 1 _, fbvals, fbvecs = get_data('small_64D') bvals = np.load(fbvals) bvecs = np.load(fbvecs) gtab = gradient_table(bvals, bvecs) mevals = np.array(([0.0015, 0.0003, 0.0003], [0.0015, 0.0003, 0.0003])) S, sticks = multi_tensor(gtab, mevals, S0, angles=[(10, 0), (100, 0)], fractions=[50, 50], snr=SNR) sphere = get_sphere('symmetric724') qb = QballModel(gtab, sh_order=8, assume_normed=True) qbfit = qb.fit(S) odf_gt = qbfit.odf(sphere) Z = np.linalg.norm(odf_gt) odfs_gt = np.zeros((3, 1, 1, odf_gt.shape[0])) odfs_gt[:, :, :] = odf_gt[:] odfs_sh = sf_to_sh(odfs_gt, sphere, sh_order=8, basis_type=None) odfs_sh /= Z fodf_sh = odf_sh_to_sharp(odfs_sh, sphere, basis=None, ratio=3 / 15., sh_order=8, lambda_=1., tau=1.) fodf = sh_to_sf(fodf_sh, sphere, sh_order=8, basis_type=None) directions2, _, _ = peak_directions(fodf[0, 0, 0], sphere) assert_equal(directions2.shape[0], 2)
def test_odf_sh_to_sharp(): SNR = None S0 = 1 _, fbvals, fbvecs = get_data('small_64D') bvals = np.load(fbvals) bvecs = np.load(fbvecs) gtab = gradient_table(bvals, bvecs) mevals = np.array(([0.0015, 0.0003, 0.0003], [0.0015, 0.0003, 0.0003])) S, sticks = multi_tensor(gtab, mevals, S0, angles=[(10, 0), (100, 0)], fractions=[50, 50], snr=SNR) sphere = get_sphere('symmetric724') qb = QballModel(gtab, sh_order=8, assume_normed=True) qbfit = qb.fit(S) odf_gt = qbfit.odf(sphere) Z = np.linalg.norm(odf_gt) odfs_gt = np.zeros((3, 1, 1, odf_gt.shape[0])) odfs_gt[:,:,:] = odf_gt[:] odfs_sh = sf_to_sh(odfs_gt, sphere, sh_order=8, basis_type=None) odfs_sh /= Z fodf_sh = odf_sh_to_sharp(odfs_sh, sphere, basis=None, ratio=3 / 15., sh_order=8, lambda_=1., tau=0.1) fodf = sh_to_sf(fodf_sh, sphere, sh_order=8, basis_type=None) directions2, _, _ = peak_directions(fodf[0, 0, 0], sphere) assert_equal(directions2.shape[0], 2)
def qball(gtab, data, name, sh_order=4): qballmodel = QballModel(gtab, sh_order) data_small = data[:, :, 39:40] qball_fit = qballmodel.fit(data_small) qball_odf = qball_fit.odf(default_sphere) odf_spheres = actor.odf_slicer(qball_odf, sphere=default_sphere, scale=0.9, norm=False, colormap='plasma') ren = window.Scene() ren.add(odf_spheres) print('Saving illustration as qball_odfs_{}.png'.format( name)) #data.shape[-1] - 1)) window.record(ren, out_path='results/qball_odfs_{}.png'.format(name), size=(600, 600)) return qball_odf, qball_fit.shm_coeff
csamodel = CsaOdfModel(gtab, 4, smooth=0.006) csa_fit = csamodel.fit(data_small) sphere = get_sphere('symmetric724') csa_odf = csa_fit.odf(sphere) gfa_csa = gfa(csa_odf) odfs = csa_odf.clip(0) gfa_csa_wo_zeros = gfa(odfs) csa_mm = minmax_normalize(odfs) gfa_csa_mm = gfa(csa_mm) qballmodel = QballModel(gtab, 6, smooth=0.006) qball_fit = qballmodel.fit(data_small) qball_odf = qball_fit.odf(sphere) gfa_qball = gfa(qball_odf) gfa_qball_mm = gfa(minmax_normalize(qball_odf)) print 'Saving GFAs...' nib.save(nib.Nifti1Image(gfa_qball.astype('float32'), affine), 'gfa.nii.gz') nib.save(nib.Nifti1Image(gfa_qball_mm.astype('float32'), affine), 'gfa_mm.nii.gz') nib.save(nib.Nifti1Image(gfa_csa.astype('float32'), affine), 'gfa_csa.nii.gz') nib.save(nib.Nifti1Image(gfa_csa_wo_zeros.astype('float32'), affine), 'gfa_csa_wo_neg.nii.gz') nib.save(nib.Nifti1Image(gfa_csa_mm.astype('float32'), affine), 'gfa_csa_mm.nii.gz') coeff = csa_fit._shm_coef
nib.save(nib.Nifti1Image(coeff.astype('float32'), affine), 'csa_odf_sh.nii.gz') sphere = get_sphere('symmetric724') odfs = sh_to_sf(coeff[20:50,55:85, 38:39], sphere, order) if vizu : from dipy.viz import fvtk r = fvtk.ren() fvtk.add(r, fvtk.sphere_funcs(odfs, sphere, colormap='jet')) fvtk.show(r) fvtk.clear(r) qballmodel = QballModel(gtab, order, smooth=0.006) print 'Computing the QBALL odf...' qballfit = qballmodel.fit(data) coeff = qballfit._shm_coef #GFA = qballfit.gfa # dipy 0.6 compatible GFA = np.sqrt(1.0 - (coeff[:,:,:,0] ** 2 / ( np.sum(np.square(coeff), axis=3) ) ) ) GFA[np.isnan(GFA)] = 0 nib.save(nib.Nifti1Image(GFA.astype('float32'), affine), 'gfa_qball.nii.gz') nib.save(nib.Nifti1Image(coeff.astype('float32'), affine), 'qball_odf_sh.nii.gz') if vizu : odfs = sh_to_sf(coeff[20:50,55:85, 38:39], sphere, order) fvtk.add(r, fvtk.sphere_funcs(odfs, sphere, colormap='jet')) fvtk.show(r) fvtk.clear(r)