def test_minmax_normalize(): bvalue = 3000 S0 = 1 SNR = 100 sphere = get_sphere("symmetric362") bvecs = np.concatenate(([[0, 0, 0]], sphere.vertices)) bvals = np.zeros(len(bvecs)) + bvalue bvals[0] = 0 gtab = gradient_table(bvals, bvecs) evals = np.array(([0.0017, 0.0003, 0.0003], [0.0017, 0.0003, 0.0003])) S, sticks = multi_tensor(gtab, evals, S0, angles=[(0, 0), (90, 0)], fractions=[50, 50], snr=SNR) odf = multi_tensor_odf(sphere.vertices, evals, angles=[(0, 0), (90, 0)], fractions=[50, 50]) odf2 = minmax_normalize(odf) assert_equal(odf2.max(), 1) assert_equal(odf2.min(), 0) odf3 = np.empty(odf.shape) odf3 = minmax_normalize(odf, odf3) assert_equal(odf3.max(), 1) assert_equal(odf3.min(), 0)
def test_minmax_normalize(): bvalue = 3000 S0 = 1 SNR = 100 sphere = get_sphere('symmetric362') bvecs = np.concatenate(([[0, 0, 0]], sphere.vertices)) bvals = np.zeros(len(bvecs)) + bvalue bvals[0] = 0 gtab = gradient_table(bvals, bvecs) evals = np.array(([0.0017, 0.0003, 0.0003], [0.0017, 0.0003, 0.0003])) multi_tensor(gtab, evals, S0, angles=[(0, 0), (90, 0)], fractions=[50, 50], snr=SNR) odf = multi_tensor_odf(sphere.vertices, evals, angles=[(0, 0), (90, 0)], fractions=[50, 50]) odf2 = minmax_normalize(odf) assert_equal(odf2.max(), 1) assert_equal(odf2.min(), 0) odf3 = np.empty(odf.shape) odf3 = minmax_normalize(odf, odf3) assert_equal(odf3.max(), 1) assert_equal(odf3.min(), 0)
mask = data[..., 0] > 50 mask_small = mask[20:50,55:85, 38:40] data_small = data[20:50,55:85, 38:40] 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')
print('GFA.shape (%d, %d, %d)' % GFA.shape) nib.save(nib.Nifti1Image(GFA.astype('float32'), affine), 'gfa.nii.gz') from dipy.data import get_sphere sphere = get_sphere('symmetric724') csa_fit = csamodel.fit(data_small) odfs = csa_fit.odf(sphere) from dipy.viz import fvtk r = fvtk.ren() fvtk.add(r, fvtk.sphere_funcs(odfs, sphere, colormap='jet')) fvtk.show(r) fvtk.clear(r) # min-max normalization csa_mm = minmax_normalize(odfs) r = fvtk.ren() fvtk.add(r, fvtk.sphere_funcs(csa_mm, sphere, colormap='jet', norm=False)) fvtk.show(r) fvtk.clear(r) # Three ways to get the GFA GFA = csapeaks.gfa GFA_sh = csa_fit.gfa GFA_odf = gfa(odfs) coeff = csa_fit._shm_coef nib.save(nib.Nifti1Image(GFA.astype('float32'), affine), 'gfa_small.nii.gz') nib.save(nib.Nifti1Image(GFA_sh.astype('float32'), affine), 'gfa_sh_small.nii.gz') nib.save(nib.Nifti1Image(GFA_sh.astype('float32'), affine), 'gfa_odf_small.nii.gz')