-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget _threshold.py
40 lines (26 loc) · 1.02 KB
/
get _threshold.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 os
from tqdm import tqdm
import SimpleITK as sitk
import sys
sys.path.append(os.path.split(sys.path[0])[0])
import parameter as para
num_point = 0.0
num_inlier = 0.0
for index, file in enumerate(os.listdir(para.train_ct_path)):
print(index,"==",file)
ct = sitk.ReadImage(os.path.join(para.train_ct_path, file), sitk.sitkInt16)
ct_array = sitk.GetArrayFromImage(ct)
seg = sitk.ReadImage(os.path.join(para.train_seg_path, file.replace('volume', 'segmentation')), sitk.sitkUInt8)
seg_array = sitk.GetArrayFromImage(seg)
liver_roi = ct_array[seg_array > 0]
inliers = ((liver_roi < para.upper) * (liver_roi > para.lower)).astype(int).sum()
print('{:.4}%'.format(inliers / liver_roi.shape[0] * 100))
print('------------')
num_point += liver_roi.shape[0]
num_inlier += inliers
print(num_inlier / num_point)
# -200 到 200 的阈值对于肝脏:训练集99.49%, 测试集99..0%
# -200 到 200 的阈值对于肿瘤:训练集99.95%, 测试集99.45%