-
Notifications
You must be signed in to change notification settings - Fork 0
/
statistical_analysis_tool.py
139 lines (90 loc) · 3.41 KB
/
statistical_analysis_tool.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
from tkinter import *
from dipy.viz import fvtk
from nibabel import trackvis
from dipy.tracking.utils import length
import numpy as np
import nibabel as nib
import vtk.util.colors as colors
import matplotlib.pyplot as plt
from dipy.tracking import utils
from dipy.tracking.vox2track import streamline_mapping
import AFQ.segmentation as seg
from tkinter import filedialog
import tkinter.messagebox
def loadtrkfile(T_filename, threshold_short_streamlines=10.0):
"""Load tractogram from TRK file and remove short streamlines with
length below threshold.
"""
print("Loading %s" % T_filename)
T, hdr = trackvis.read(T_filename, as_generator=False)
T = np.array([s[0] for s in T], dtype=np.object)
return T, hdr
def tract(segmented_tract, color):
ren = fvtk.ren()
fvtk.add(ren, fvtk.line(segmented_tract.tolist(),colors=color, linewidth=2,opacity=0.3))
fvtk.show(ren)
fvtk.clear(ren)
def input_tract():
global T_A,hdr,T_A_filename,color
T_A_filename= filedialog.askopenfilename()
threshold_short_streamlines = 0.0
T_A, hdr = loadtrkfile(T_A_filename, threshold_short_streamlines=threshold_short_streamlines)
color=colors.red
def input_image():
global img
img= filedialog.askopenfilename()
def show_tract():
tract(T_A, color)
def countstreamlines():
print("---Number of streamlines---")
print(( len(T_A)))
tkinter.messagebox.showinfo("Streamlines", ( len(T_A)))
def voxelCount():
tractography,header=trackvis.read(T_A_filename)
tractography = [streamline[0] for streamline in tractography]
affine=utils.affine_for_trackvis(voxel_size=np.array([2,2,2]))
print ("---Number of voxel---")
print (len(streamline_mapping(T_A,affine=affine).keys()))
tkinter.messagebox.showinfo("Voxel", len(streamline_mapping(T_A,affine=affine).keys()))
def showhistogram():
print("Histogram...")
lengths = list(length(T_A))
fig_hist, ax = plt.subplots()
ax.hist(lengths, color='burlywood')
ax.set_xlabel('Length')
ax.set_ylabel('Count')
plt.show()
def showAfq():
FA_img = nib.load(img)
FA_data = FA_img.get_data()
print("Tract profiles...")
fig, ax = plt.subplots(1)
profile = seg.calculate_tract_profile(FA_data, T_A.tolist())
ax.plot(profile)
#ax.set_title('100307_af.left')
#plt.savefig("F:\Thesis\DATA\\103414_af.left.png")
plt.show()
if __name__ == '__main__':
print(__doc__)
np.random.seed(0)
root = Tk()
root.geometry("500x200")
root.title("TRACTOGRAPHY")
Frame= Frame(root)
Frame.pack(fill=X)
button1=Button(Frame,text="Load Tract",fg="blue",command=input_tract)
button=Button(Frame,text="Load Image",fg="blue",command=input_image)
button2=Button(Frame,text="Show Tract",fg="blue",command=show_tract)
button3=Button(Frame,text="Streamlines Count",fg="blue",command=countstreamlines)
button4=Button(Frame,text="Voxel Count",fg="blue",command=voxelCount)
button5=Button(Frame,text="Show Histogram",fg="blue",command=showhistogram)
button6=Button(Frame,text="Show Profile",fg="blue",command=showAfq)
button1.pack(fill=X)
button.pack(fill=X)
button2.pack(fill=X)
button3.pack(fill=X)
button4.pack(fill=X)
button5.pack(fill=X)
button6.pack(fill=X)
button6.pack(fill=X)
root.mainloop()