示例#1
0
def show_sph_grid():
    r=fvtk.ren()
    print verts.shape, faces.shape
    sph=np.abs(np.dot(gradients[1],verts.T)**2)
    print sph.shape
    cols=fvtk.colors(sph,'jet')
    #fvtk.add(r,fvtk.point(verts,cols,point_radius=.1,theta=10,phi=10))
    
    for (i,v) in enumerate(gradients):    
        fvtk.label(r,str(i),pos=v,scale=(.02,.02,.02))
        if i in [62,76,58]:
            fvtk.label(r,str(i),pos=v,scale=(.05,.05,.05),color=(1,0,0))
    fvtk.show(r)
示例#2
0
def simulations_marta(): 

    #gq_tn_calc_save()
    #a_few_phantoms()
    
    #sd=['fibres_2_SNR_100_angle_60_l1_1.4_l2_0.35_l3_0.35_iso_0_diso_00']
    #sd=['fibres_2_SNR_60_angle_60_l1_1.4_l2_0.35_l3_0.35_iso_0_diso_00']
    #sd=['fibres_2_SNR_100_angle_60_l1_1.4_l2_0.35_l3_0.35_iso_1_diso_0.7']
    sd=['fibres_2_SNR_100_angle_90_l1_1.4_l2_0.35_l3_0.35_iso_0_diso_00']
    #sd=['fibres_1_SNR_100_angle_00_l1_1.4_l2_0.35_l3_0.35_iso_0_diso_00']
    #sd=['fibres_2_SNR_20_angle_90_l1_1.4_l2_0.35_l3_0.35_iso_0_diso_00']
    #for simfile in simdata:
    
    np.set_printoptions(2)
    
    dotpow=6
    width=6
    sincpow=2
    sampling_length=1.2
    
    print dotpow,width,sincpow
    print sampling_length
    
    verts,faces=get_sphere('symmetric362')
    
    for simfile in sd:
        
        data=np.loadtxt(simdir+simfile)
        sf=simfile.split('_')        
        b_vals_dirs=np.loadtxt(simdir+'Dir_and_bvals_DSI_marta.txt')
        bvals=b_vals_dirs[:,0]*1000
        gradients=b_vals_dirs[:,1:]
            
        data2=data[::1000,:]   
        
        table={'fibres':sf[1],'snr':sf[3],'angle':sf[5],'l1':sf[7],'l2':sf[9],\
               'l3':sf[11],'iso':sf[13],'diso':sf[15],\
               'data':data2,'bvals':bvals,'gradients':gradients}
        
        print table['data'].shape
        pdi=ProjectiveDiffusivity(table['data'],table['bvals'],table['gradients'],dotpow,width,sincpow)
        gqs=GeneralizedQSampling(table['data'],table['bvals'],table['gradients'],sampling_length)
        ten=Tensor(table['data'],table['bvals'],table['gradients'])
        r=fvtk.ren()
        
        for i in range(10):#range(len(sdi.xa())):
            
            print 'No:',i
            print 'simulation fibres ',table['fibres'], ' snr ',table['snr'],' angle ', table['angle']
            pdiind=pdi.ind()[i]
            gqsind=gqs.ind()[i]
            
            print 'indices',pdiind,gqsind,\
                np.rad2deg(np.arccos(np.dot(verts[pdiind[0]],verts[pdiind[1]]))),\
                np.rad2deg(np.arccos(np.dot(verts[gqsind[0]],verts[gqsind[1]])))
                
            #ten.ind()[i],
            print 'peaks', pdi.xa()[i]*10**3,gqs.qa()[i]
            
            pd=pdi.spherical_diffusivity(table['data'][i])#*10**3
            #print 'pd stat',pd.min(),pd.max(),pd.mean(),pd.std()
            
            #colors=fvtk.colors(sdf,'jet')
            sdfcol=np.interp(pd,[pd.mean()-4*pd.std(),pd.mean()+4*pd.std()],[0,1])
            colors=fvtk.colors(sdfcol,'jet',False)        
            fvtk.add(r,fvtk.point(5*pdi.odf_vertices+np.array([12*i,0,0]),colors,point_radius=.6,theta=10,phi=10))
            
            odf=gqs.odf(table['data'][i])
            colors=fvtk.colors(odf,'jet')
            fvtk.add(r,fvtk.point(5*gqs.odf_vertices+np.array([12*i,-12,0]),colors,point_radius=.6,theta=10,phi=10))
             
        fvtk.show(r)
示例#3
0
def test():

    # img=nib.load('/home/eg309/Data/project01_dsi/connectome_0001/tp1/RAWDATA/OUT/mr000001.nii.gz')
    btable = np.loadtxt(get_data("dsi515btable"))
    # volume size
    sz = 16
    # shifting
    origin = 8
    # hanning width
    filter_width = 32.0
    # number of signal sampling points
    n = 515
    # odf radius
    radius = np.arange(2.1, 6, 0.2)
    # create q-table
    bv = btable[:, 0]
    bmin = np.sort(bv)[1]
    bv = np.sqrt(bv / bmin)
    qtable = np.vstack((bv, bv, bv)).T * btable[:, 1:]
    qtable = np.floor(qtable + 0.5)
    # copy bvals and bvecs
    bvals = btable[:, 0]
    bvecs = btable[:, 1:]
    # S=img.get_data()[38,50,20]#[96/2,96/2,20]
    S, stics = SticksAndBall(
        bvals, bvecs, d=0.0015, S0=100, angles=[(0, 0), (60, 0), (90, 90)], fractions=[0, 0, 0], snr=None
    )

    S2 = S.copy()
    S2 = S2.reshape(1, len(S))
    dn = DiffusionNabla(S2, bvals, bvecs, auto=False)
    pR = dn.equators
    odf = dn.odf(S)
    # Xs=dn.precompute_interp_coords()
    peaks, inds = peak_finding(odf.astype("f8"), dn.odf_faces.astype("uint16"))
    print peaks
    print peaks / peaks.min()
    # print dn.PK
    dn.fit()
    print dn.PK

    # """
    ren = fvtk.ren()
    colors = fvtk.colors(odf, "jet")
    fvtk.add(ren, fvtk.point(dn.odf_vertices, colors, point_radius=0.05, theta=8, phi=8))
    fvtk.show(ren)
    # """

    stop

    # ds=DiffusionSpectrum(S2,bvals,bvecs)
    # tpr=ds.pdf(S)
    # todf=ds.odf(tpr)

    """
    #show projected signal
    Bvecs=np.concatenate([bvecs[1:],-bvecs[1:]])
    X0=np.dot(np.diag(np.concatenate([S[1:],S[1:]])),Bvecs)    
    ren=fvtk.ren()
    fvtk.add(ren,fvtk.point(X0,fvtk.yellow,1,2,16,16))    
    fvtk.show(ren)
    """
    # qtable=5*matrix[:,1:]

    # calculate radius for the hanning filter
    r = np.sqrt(qtable[:, 0] ** 2 + qtable[:, 1] ** 2 + qtable[:, 2] ** 2)

    # setting hanning filter width and hanning
    hanning = 0.5 * np.cos(2 * np.pi * r / filter_width)

    # center and index in q space volume
    q = qtable + origin
    q = q.astype("i8")

    # apply the hanning filter
    values = S * hanning

    """
    #plot q-table
    ren=fvtk.ren()
    colors=fvtk.colors(values,'jet')
    fvtk.add(ren,fvtk.point(q,colors,1,0.1,6,6))
    fvtk.show(ren)
    """

    # create the signal volume
    Sq = np.zeros((sz, sz, sz))
    for i in range(n):
        Sq[q[i][0], q[i][1], q[i][2]] += values[i]

    # apply fourier transform
    Pr = fftshift(np.abs(np.real(fftn(fftshift(Sq), (sz, sz, sz)))))

    # """
    ren = fvtk.ren()
    vol = fvtk.volume(Pr)
    fvtk.add(ren, vol)
    fvtk.show(ren)
    # """

    """
    from enthought.mayavi import mlab
    mlab.pipeline.volume(mlab.pipeline.scalar_field(Sq))
    mlab.show()
    """

    # vertices, edges, faces  = create_unit_sphere(5)
    vertices, faces = sphere_vf_from("symmetric362")
    odf = np.zeros(len(vertices))

    for m in range(len(vertices)):

        xi = origin + radius * vertices[m, 0]
        yi = origin + radius * vertices[m, 1]
        zi = origin + radius * vertices[m, 2]
        PrI = map_coordinates(Pr, np.vstack((xi, yi, zi)), order=1)
        for i in range(len(radius)):
            odf[m] = odf[m] + PrI[i] * radius[i] ** 2

    """
    ren=fvtk.ren()
    colors=fvtk.colors(odf,'jet')
    fvtk.add(ren,fvtk.point(vertices,colors,point_radius=.05,theta=8,phi=8))
    fvtk.show(ren)
    """

    """
    #Pr[Pr<500]=0    
    ren=fvtk.ren()
    #ren.SetBackground(1,1,1)
    fvtk.add(ren,fvtk.volume(Pr))
    fvtk.show(ren)
    """

    peaks, inds = peak_finding(odf.astype("f8"), faces.astype("uint16"))

    Eq = np.zeros((sz, sz, sz))
    for i in range(n):
        Eq[q[i][0], q[i][1], q[i][2]] += S[i] / S[0]

    LEq = laplace(Eq)

    # Pr[Pr<500]=0
    ren = fvtk.ren()
    # ren.SetBackground(1,1,1)
    fvtk.add(ren, fvtk.volume(Eq))
    fvtk.show(ren)

    phis = np.linspace(0, 2 * np.pi, 100)

    planars = []
    for phi in phis:
        planars.append(sphere2cart(1, np.pi / 2, phi))
    planars = np.array(planars)

    planarsR = []
    for v in vertices:
        R = vec2vec_rotmat(np.array([0, 0, 1]), v)
        planarsR.append(np.dot(R, planars.T).T)

    """
    ren=fvtk.ren()
    fvtk.add(ren,fvtk.point(planarsR[0],fvtk.green,1,0.1,8,8))
    fvtk.add(ren,fvtk.point(2*planarsR[1],fvtk.red,1,0.1,8,8))
    fvtk.show(ren)
    """

    azimsums = []
    for disk in planarsR:
        diskshift = 4 * disk + origin
        # Sq0=map_coordinates(Sq,diskshift.T,order=1)
        # azimsums.append(np.sum(Sq0))
        # Eq0=map_coordinates(Eq,diskshift.T,order=1)
        # azimsums.append(np.sum(Eq0))
        LEq0 = map_coordinates(LEq, diskshift.T, order=1)
        azimsums.append(np.sum(LEq0))

    azimsums = np.array(azimsums)

    # """
    ren = fvtk.ren()
    colors = fvtk.colors(azimsums, "jet")
    fvtk.add(ren, fvtk.point(vertices, colors, point_radius=0.05, theta=8, phi=8))
    fvtk.show(ren)
    # """

    # for p in planarsR[0]:
    """
示例#4
0
            #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:,:]

print sphere_dic.keys()

#vertices = get_vertex_set('create5')
#vertices = get_vertex_set('siem64')
#vertices = get_vertex_set('dsi102')

vertices = get_vertex_set('fy362')
gradients = get_vertex_set('siem64')
gradients = gradients[:gradients.shape[0]/2]
print gradients.shape

from dipy.viz import fvtk
sph=-np.sinc(np.dot(gradients[1],vertices.T))
r=fvtk.ren()
#sph = np.arange(vertices.shape[0]) 
print sph.shape
cols=fvtk.colors(sph,'jet')
fvtk.add(r,fvtk.point(vertices,cols,point_radius=.1,theta=10,phi=10))
fvtk.show(r)

示例#5
0
文件: get_vertices.py 项目: wrgr/dipy
            #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:, :]


print sphere_dic.keys()

#vertices = get_vertex_set('create5')
#vertices = get_vertex_set('siem64')
#vertices = get_vertex_set('dsi102')

vertices = get_vertex_set('fy362')
gradients = get_vertex_set('siem64')
gradients = gradients[:gradients.shape[0] / 2]
print gradients.shape

from dipy.viz import fvtk
sph = -np.sinc(np.dot(gradients[1], vertices.T))
r = fvtk.ren()
#sph = np.arange(vertices.shape[0])
print sph.shape
cols = fvtk.colors(sph, 'jet')
fvtk.add(r, fvtk.point(vertices, cols, point_radius=.1, theta=10, phi=10))
fvtk.show(r)