-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.py
executable file
·45 lines (40 loc) · 1.25 KB
/
demo.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
# -*- coding: utf-8 -*-
# Author = ZRHonor
# import os
import cv2
import data
import seg_pneum
import sys
import os
MODE_TEST = 1
MODE_ALL = 0
mode = MODE_TEST
root_path = '../data/6/'
print("root_path: ", root_path)
if mode == MODE_ALL:
# folder mode
pneum_areas = []
lung_areas = []
files = os.listdir(root_path)
files.sort()
for file in files:
print(file)
fileName = root_path + file
img = data.load_dcm(fileName)
flag, pneum_area, lung_area = seg_pneum.seg_pneum(img)
pneum_areas.append(pneum_area)
lung_areas.append(lung_area)
print("flag: ", flag, "\tpneum area: ", pneum_area, "\tlung_area: ", lung_area)
cv2.waitKey(100)
total_pneum_area = sum(filter(None, pneum_areas))
total_lung_area = sum(filter(None, lung_areas))
print("================================")
print('ratio: ', total_pneum_area / total_lung_area)
else:
# single test
fileName = root_path + "14.dcm"
img = data.load_dcm(fileName)
flag, pneum_area, lung_area = seg_pneum.seg_pneum(img)
print("flag: ", flag, "\tpneum area: ", pneum_area, "\tlung_area: ", lung_area)
cv2.waitKey()
print('ratio: ', pneum_area / lung_area)