-
Notifications
You must be signed in to change notification settings - Fork 0
/
concentration.py
41 lines (31 loc) · 1.17 KB
/
concentration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import numpy as np
from dipy.core import track_metrics as tm
import dipy.core.performance as pf
import numpy.linalg as npla
import pbc
'''
path='/home/eg01/Data/PBC/pbc2009icdm'
G,hdr,R,relR,ref = pbc.load_training_set_plus(path)
hits = pbc.load_pickle(path+'/hits.pkl')
b=8
plane_hits=hits[b][0]
'''
def concs(plane_hits,ref):
'''
calculates the log detrminant of the concentration matrix for the hits in planehits
'''
dispersions = [np.prod(np.sort(npla.eigvals(np.cov(p[:,0:3].T)))[1:2]) for p in plane_hits]
index = np.argmin(dispersions)
log_concentration = -np.log2(dispersions[index])
centre = ref[index+1]
return index, centre, log_concentration
def refconc(brain, ref):
'''
given a reference fibre locates the parallel fibres in brain (tracks)
with threshold_hitdata applied to cut_planes output then follows
with concentration to locate the locus of a neck
'''
hitdata = pf.cut_plane(brain, ref)
reduced_hitdata, heavy_weight_fibres = tl.threshold_hitdata(hitdata, divergence_threshold=0.2, fibre_weight=0.9)
index, centre, conc = concs(reduced_hitdata, ref)
return heavy_weight_fibres, index, centre