-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathvis.py
99 lines (76 loc) · 3.58 KB
/
vis.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
# import matplotlib
# matplotlib.use('nbagg')
import numpy as np
import matplotlib.pyplot as plt
from p2ch12.dsets import Ct, LunaDataset
clim=(-1000.0, 300)
def findPositiveSamples(start_ndx=0, limit=10):
ds = LunaDataset(sortby_str='label_and_size')
positiveSample_list = []
for sample_tup in ds.candidateInfo_list:
if sample_tup.isNodule_bool:
print(len(positiveSample_list), sample_tup)
positiveSample_list.append(sample_tup)
if len(positiveSample_list) >= limit:
break
return positiveSample_list
def showCandidate(series_uid, batch_ndx=None, **kwargs):
ds = LunaDataset(series_uid=series_uid, **kwargs)
pos_list = [i for i, x in enumerate(ds.candidateInfo_list) if x.isNodule_bool]
if batch_ndx is None:
if pos_list:
batch_ndx = pos_list[0]
else:
print("Warning: no positive samples found; using first negative sample.")
batch_ndx = 0
ct = Ct(series_uid)
ct_t, pos_t, series_uid, center_irc = ds[batch_ndx]
ct_a = ct_t[0].numpy()
fig = plt.figure(figsize=(30, 50))
group_list = [
[9, 11, 13],
[15, 16, 17],
[19, 21, 23],
]
subplot = fig.add_subplot(len(group_list) + 2, 3, 1)
subplot.set_title('index {}'.format(int(center_irc.index)), fontsize=30)
for label in (subplot.get_xticklabels() + subplot.get_yticklabels()):
label.set_fontsize(20)
plt.imshow(ct.hu_a[int(center_irc.index)], clim=clim, cmap='gray')
subplot = fig.add_subplot(len(group_list) + 2, 3, 2)
subplot.set_title('row {}'.format(int(center_irc.row)), fontsize=30)
for label in (subplot.get_xticklabels() + subplot.get_yticklabels()):
label.set_fontsize(20)
plt.imshow(ct.hu_a[:,int(center_irc.row)], clim=clim, cmap='gray')
plt.gca().invert_yaxis()
subplot = fig.add_subplot(len(group_list) + 2, 3, 3)
subplot.set_title('col {}'.format(int(center_irc.col)), fontsize=30)
for label in (subplot.get_xticklabels() + subplot.get_yticklabels()):
label.set_fontsize(20)
plt.imshow(ct.hu_a[:,:,int(center_irc.col)], clim=clim, cmap='gray')
plt.gca().invert_yaxis()
subplot = fig.add_subplot(len(group_list) + 2, 3, 4)
subplot.set_title('index {}'.format(int(center_irc.index)), fontsize=30)
for label in (subplot.get_xticklabels() + subplot.get_yticklabels()):
label.set_fontsize(20)
plt.imshow(ct_a[ct_a.shape[0]//2], clim=clim, cmap='gray')
subplot = fig.add_subplot(len(group_list) + 2, 3, 5)
subplot.set_title('row {}'.format(int(center_irc.row)), fontsize=30)
for label in (subplot.get_xticklabels() + subplot.get_yticklabels()):
label.set_fontsize(20)
plt.imshow(ct_a[:,ct_a.shape[1]//2], clim=clim, cmap='gray')
plt.gca().invert_yaxis()
subplot = fig.add_subplot(len(group_list) + 2, 3, 6)
subplot.set_title('col {}'.format(int(center_irc.col)), fontsize=30)
for label in (subplot.get_xticklabels() + subplot.get_yticklabels()):
label.set_fontsize(20)
plt.imshow(ct_a[:,:,ct_a.shape[2]//2], clim=clim, cmap='gray')
plt.gca().invert_yaxis()
for row, index_list in enumerate(group_list):
for col, index in enumerate(index_list):
subplot = fig.add_subplot(len(group_list) + 2, 3, row * 3 + col + 7)
subplot.set_title('slice {}'.format(index), fontsize=30)
for label in (subplot.get_xticklabels() + subplot.get_yticklabels()):
label.set_fontsize(20)
plt.imshow(ct_a[index], clim=clim, cmap='gray')
print(series_uid, batch_ndx, bool(pos_t[0]), pos_list)