-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutils.py
41 lines (26 loc) · 886 Bytes
/
utils.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
import numpy as np
import cv2
def dice_metric(A, B):
intersect = np.sum(A * B)
fsum = np.sum(A)
ssum = np.sum(B)
dice = (2 * intersect ) / (fsum + ssum)
return dice
def hm_metric(A, B):
intersection = A * B
union = np.logical_or(A, B)
hm_score = (np.sum(union) - np.sum(intersection)) / np.sum(union)
return hm_score
def xor_metric(A, GT):
intersection = A * GT
union = np.logical_or(A, GT)
xor_score = (np.sum(union) - np.sum(intersection)) / np.sum(GT)
return xor_score
def create_mask(pred, GT):
kernel = np.ones((7,7),np.uint8)
dilated_GT = cv2.dilate(GT, kernel, iterations = 2)
mult = pred * GT
unique, count = np.unique(mult[mult !=0], return_counts=True)
cls= unique[np.argmax(count)]
lesion = np.where(pred==cls, 1, 0) * dilated_GT
return lesion