-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_end.py
91 lines (86 loc) · 3.37 KB
/
main_end.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
import os, copy
import numpy as np
import shutil
def find_abnormal_data(temp,limit): #寻找不正常数据
vaule_mean = temp.mean()
cnt = 0
temp_out = []
for n in temp:
if limit > 0:
if (n-vaule_mean)/n > limit:
temp_out.append(1)
else:
temp_out.append(0)
else:
if (n-vaule_mean)/n < limit:
temp_out.append(1)
else:
temp_out.append(0)
cnt = cnt + 1
temp_out = np.array(temp_out)
return temp_out
def get_sign(cells_info_file): #解析细胞信息
cells_info = np.load(cells_info_file)
nuclei_area_ = []
nuclei_rule_ = []
nuclei_value_ = []
cytoplasm_area_ = []
cytoplasm_rule_ = []
cytoplasm_value_ = []
cell_N_C_ = []
for n in cells_info:
nuclei_area = n['nuclei_area']
nuclei_area_.append(nuclei_area)
nuclei_rule = n['nuclei_rule']
nuclei_rule_.append(nuclei_rule)
nuclei_value = n['cell_nuclei_value']
nuclei_value_.append(nuclei_value)
cytoplasm_area = n['cytoplasm_area']
cytoplasm_area_.append(cytoplasm_area)
cytoplasm_rule = n['cytoplasm_rule']
cytoplasm_rule_.append(cytoplasm_rule)
cytoplasm_value = n['cell_cytoplasm_value']
cytoplasm_value_.append(cytoplasm_value)
cell_N_C = n['cell_N_C']
cell_N_C_.append(cell_N_C)
nuclei_area_ = np.array(nuclei_area_)
nuclei_rule_ = np.array(nuclei_rule_)
nuclei_value_ = np.array(nuclei_value_)
cytoplasm_area_ = np.array(cytoplasm_area_)
cytoplasm_rule_ = np.array(cytoplasm_rule_)
cytoplasm_value_ = np.array(cytoplasm_value_)
cell_N_C_ = np.array(cell_N_C_)
nuclei_area_abnormal = find_abnormal_data(nuclei_area_, 0.4) #单项阈值
nuclei_rule_abnormal = find_abnormal_data(nuclei_rule_, 100)
nuclei_value_abnormal = find_abnormal_data(nuclei_value_, 100)
cytoplasm_area_abnormal = find_abnormal_data(cytoplasm_area_, 100)
cytoplasm_rule_abnormal = find_abnormal_data(cytoplasm_rule_, 100)
cytoplasm_value_abnormal = find_abnormal_data(cytoplasm_value_, 100)
cell_N_C_abnormal = find_abnormal_data(cell_N_C_, 0.6)
cells_infos = []
cells_infos = [nuclei_area_abnormal, nuclei_rule_abnormal, nuclei_value_abnormal, cytoplasm_area_abnormal, cytoplasm_rule_abnormal, cytoplasm_value_abnormal, cell_N_C_abnormal]
cells_infos = np.array(cells_infos)
cells_infos_2 = cells_infos.copy()
cells_infos_2[0,:] = cells_infos[0,:] * 50 #综合权重
cells_infos_2[1,:] = cells_infos[1,:] * 0
cells_infos_2[2,:] = cells_infos[2,:] * 0
cells_infos_2[3,:] = cells_infos[3,:] * 0
cells_infos_2[4,:] = cells_infos[4,:] * 0
cells_infos_2[5,:] = cells_infos[5,:] * 0
cells_infos_2[6,:] = cells_infos[6,:] * 50
cells_infos_2 = np.array(cells_infos_2)
cnt_2 = 0
for n in range(0, cells_infos_2.shape[1]):
sum_ = sum(cells_infos_2[:,n])
if sum_ >= 100:
cellpath = cells_info[n]['cellpath']
newpath = os.path.join('cells_abnormal', cellpath.split('/')[1])
shutil.copy(cellpath, newpath)
cnt_2 = cnt_2 + 1
sign = 0
if cnt_2 > 10: #不正常细胞个数大于10认为为阳性病例
sign = 1
return sign
if __name__ == "__main__":
cells_info_file = 'cells_info/cells_info.npy'
get_sign(cells_info_file)