예제 #1
0
def test_create_unit_sphere():
    v, e, t = create_unit_sphere(7)
    assert_array_equal(v[::2], -v[1::2])
    assert_array_equal(v[e[::2]], -v[e[1::2]])
    assert_array_equal(v[e[t[::2]]], -v[e[t[1::2]]])
    assert_array_almost_equal((v * v).sum(1), 1)
    assert_array_equal(e[t, 0], np.roll(e[t, 1], 1, 1))
예제 #2
0
def get_vertex_set(key):

    if key[:6] == 'create':
        number = eval(key[6:])
        vertices, edges, faces = create_unit_sphere(number) 
        omit = 0
        return vertices
    else:
        entry = sphere_dic[key]

        if entry.has_key('omit'):
            omit = entry['omit']
        else:
            omit = 0
        filepath = entry['filepath']
        if entry['object'] == 'npz':
            filearray  = np.load(filepath)
            vertices = filearray[entry['vertices']]
        elif sphere_dic[key]['object'] == 'npy':
            vertices = np.load(filepath)
        elif entry['object'] == 'dicom':
            data,affine,bvals,gradients=dcm.read_mosaic_dir(filepath)
            #print (bvals.shape, gradients.shape)
            grad3 = np.vstack((bvals,bvals,bvals)).transpose()
            #print grad3.shape
            #vertices = grad3*gradients
            vertices = gradients
        if omit > 0:
            vertices = vertices[omit:,:]
        if entry['hemi']:
            vertices = np.vstack([vertices, -vertices])

        return vertices[omit:,:]
def main():
    #set some values to be used later
    sh_order = 6
    verts, edges, efaces = create_unit_sphere(4)

    #read_data from disk
    data, fa, bvec, bval, voxel_size = sample_hardi_data()
    data_slice = data[32:76, 32:76, 26:27]
    fa_slice = fa[32:76, 32:76, 26]

    #normalize data by dividing by b0, this is needed so we can take log later
    norm_data = normalize_data(data_slice, bval, min_signal=1)

    #create an instance of the model
    model_instance = MonoExpOpdfModel(sh_order, bval, bvec, .006)
    model_instance.set_sampling_points(verts, edges)

    #use the model it fit the data
    opdfs_sampled_at_verts = model_instance.evaluate(norm_data)
    opdfs_sph_harm_coef = model_instance.fit_data(norm_data)

    #display the opdf blobs using mayavi
    faces = edges[efaces, 0]
    show_blobs(opdfs_sampled_at_verts, verts, faces)
    mlab.imshow(fa_slice, colormap='gray', interpolate=False)
    mlab.show()
예제 #4
0
def get_vertex_set(key):
    if key[:6] == 'create':
        number = eval(key[6:])
        vertices, edges, faces = create_unit_sphere(number)
        omit = 0
    else:
        entry = sphere_dic[key]
        #print entry
        if entry.has_key('omit'):
            omit = entry['omit']
        else:
            omit = 0
        filepath = entry['filepath']
        if entry['object'] == 'npz':
            filearray = np.load(filepath)
            vertices = filearray[entry['vertices']]
        elif sphere_dic[key]['object'] == 'npy':
            vertices = np.load(filepath)
        elif entry['object'] == 'dicom':
            data, affine, bvals, gradients = dcm.read_mosaic_dir(filepath)
            #print (bvals.shape, gradients.shape)
            grad3 = np.vstack((bvals, bvals, bvals)).transpose()
            #print grad3.shape
            #vertices = grad3*gradients
            vertices = gradients
        if omit > 0:
            vertices = vertices[omit:, :]
        if entry['hemi']:
            vertices = np.vstack([vertices, -vertices])
    print key, ': number of vertices = ', vertices.shape[
        0], '(drop ', omit, ')'
    return vertices[omit:, :]
예제 #5
0
def test_create_unit_sphere():
    v, e, t = create_unit_sphere(7)
    assert_array_equal(v[::2], -v[1::2])
    assert_array_equal(v[e[::2]], -v[e[1::2]])
    assert_array_equal(v[e[t[::2]]], -v[e[t[1::2]]])
    assert_array_almost_equal((v*v).sum(1), 1)
    assert_array_equal(e[t,0], np.roll(e[t, 1], 1, 1))
예제 #6
0
from sphdif.coord import car2sph, sph2car

from dipy.sims.voxel import multi_tensor_odf
from dipy.reconst.shm import SlowAdcOpdfModel, MonoExpOpdfModel, QballOdfModel

coords = sph_io.load('sphere_pts.npz')

#from dipy.data import get_sphere
#verts, faces = get_sphere('symmetric724')

## from dipy.core.triangle_subdivide import create_unit_sphere
## verts, edges, sides = create_unit_sphere(5)
## faces = edges[sides, 0]

from dipy.core.triangle_subdivide import create_unit_sphere
verts, edges, sides = create_unit_sphere(5)
faces = edges[sides, 0]

theta, phi, r = car2sph(*verts.T)

sampling_xyz = np.column_stack(
    sph2car(coords['gradient_theta'], coords['gradient_phi'])
    )


## verts = np.column_stack(sph2car(theta, phi))
## from dipy.core.meshes import faces_from_vertices
## faces = faces_from_vertices(verts)

def separation_from_odf(odf):
    # Find angles
예제 #7
0
def create_half_unit_sphere():
    v, e, t = create_unit_sphere(7)
    assert_array_almost_equal((v * v).sum(1), 1)
    assert_array_equal(e[t, 0], np.roll(e[t, 1], 1, 1))
예제 #8
0
def create_half_unit_sphere():
    v, e, t = create_unit_sphere(7)
    assert_array_almost_equal((v*v).sum(1), 1)
    assert_array_equal(e[t,0], np.roll(e[t, 1], 1, 1))
예제 #9
0
파일: pf_script.py 프로젝트: stefanv/dipy
import numpy as np
from dipy.core.reconstruction_performance import peak_finding
from dipy.core.reconstruction_performance import pf_bago

from dipy.core.triangle_subdivide import create_unit_sphere, remove_half_sphere

v, e, t = create_unit_sphere(5)
vH, eH, tH = remove_half_sphere(v, e, t)

odf = np.random.random(len(vH))

pB, iB = pf_bago(odf, eH)

bO = np.r_[odf, odf]
faces = e[t, 0]
faces = faces / 2 + (faces % 2) * len(odf)

p, i = peak_finding(bO, faces)
예제 #10
0
    # ================
    # Q-Space Sampling
    # ================

    # Note: We sample our signal in Q-space on the low-order quadrature points
    # here, but wwe could just as well have used other, random points on the
    # sphere.

    E = w[0] * single_tensor(gradients=xyz, bvals=b, S0=1, rotation=R0, SNR=SNR)
    E += w[1] * single_tensor(gradients=xyz, bvals=b, S0=1, rotation=R1, SNR=SNR)

    print "Signal mean:", E.mean()

    if visualize_signal:
        from dipy.core.triangle_subdivide import create_unit_sphere
        sphere = create_unit_sphere(6)
        bb = np.ones(len(sphere.vertices)) * b.mean()

        E_ = w[0] * single_tensor(gradients=sphere.vertices, bvals=bb, S0=1, rotation=R0, SNR=SNR)
        E_ += w[1] * single_tensor(gradients=sphere.vertices, bvals=bb, S0=1, rotation=R1, SNR=SNR)

        ODF = w[0] * single_tensor_ODF(sphere.vertices, rotation=R0)
        ODF += w[1] * single_tensor_ODF(sphere.vertices, rotation=R1)

        from dipy.viz import show_odfs
        show_odfs([[[E_, ODF]]], (sphere.vertices, sphere.faces))


    if visualize_odf:
        plot_ODF(grid_density=D)
        mlab = plot.get_mlab()