-
Notifications
You must be signed in to change notification settings - Fork 6
/
evaluate.py
110 lines (91 loc) · 3.29 KB
/
evaluate.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
import numpy as np
import skimage.io as io
import os
def dice_score(path1, path2, num_image):
area_A = 0
area_B = 0
area_C = 0
sum = 0
for i in range(num_image):
img1 = io.imread(os.path.join(path1,"%d.jpg"%i),as_grey = True)
img2 = io.imread(os.path.join(path2,"%d.jpg"%i),as_grey = True)
img2=img2.astype("float64")
for a in range(512):
for b in range(512):
if img1[a, b] > 0.0:
area_A = area_A + 1
print area_A
for a in range(512):
for b in range(512):
if img2[a, b] > 0.0:
area_B = area_B + 1
print area_B
for a in range(512):
for b in range(512):
if img1[a, b] > 0.0 and img2[a, b] > 0.0:
area_C = area_C + 1
print area_C
# if area_A == 0.0 and area_B == 0.0:
# dice = 1
dice = (2.0 * area_C)/(area_A + area_B + 0.0)
sum = sum + dice
print 'Dice_score{}: {}'.format(i, dice)
avg = sum / num_image
print 'Dice_avg: {}'.format(avg)
print '--------------------------------------------------------'
def voe_err(path1, path2, num_image):
area_C = 0
area_D = 0
sum1 = 0
for i in range(num_image):
img1 = io.imread(os.path.join(path1,"%d.jpg"%i),as_grey = True)
img2 = io.imread(os.path.join(path2,"%d.jpg"%i),as_grey = True)
img2 = np.float64(img2)
for a in range(512):
for b in range(512):
if img1[a, b] > 0.0 and img2[a, b] > 0.0:
area_C = area_C + 1
# print area_C
for a in range(512):
for b in range(512):
if img1[a, b] > 0.0 or img2[a, b] > 0.0:
area_D = area_D + 1
# print area_D
voe = 1.0 - area_C / (area_D + 0.0)
sum1 = sum1 + voe
print 'Voe_err{}: {}'.format(i, 1.0 - area_C / (area_D + 0.0))
print 'sum:{}'.format(sum1)
avg = sum1 / num_image
print 'Voe_avg: {}'.format(avg)
print '--------------------------------------------------------'
def rvd_err(path1, path2, num_image):
area_A = 0
area_B = 0
sum = 0
for i in range(num_image):
img1 = io.imread(os.path.join(path1, "%d.jpg" % i), as_grey=True)
img2 = io.imread(os.path.join(path2, "%d.jpg" % i), as_grey=True)
img2 = np.float64(img2)
for a in range(512):
for b in range(512):
if img1[a, b] > 0.0:
area_A = area_A + 1
# print area_A
for a in range(512):
for b in range(512):
if img2[a, b] > 0.0:
area_B = area_B + 1
# print area_B
rvd = (area_B - area_A + 0.0) / (area_A + 0.0)
sum = sum + rvd
print 'Rvd_err{}: {}'.format(i, (area_B - area_A + 0.0) / (area_A + 0.0))
avg = sum / num_image
print 'Rvd_avg: {}'.format(avg)
print '--------------------------------------------------------'
if __name__ == '__main__':
path1 = '/ext/xhzhao/Unet-CT/evaluation/full_tumor_prediction'
path2 = '/ext/xhzhao/Unet-CT/evaluation/full_tumor_label'
num_image = 30
# dice_score(path1, path2, num_image)
voe_err(path1, path2, num_image)
# rvd_err(path1, path2, num_image)