-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathmetrics.py
52 lines (35 loc) · 1 KB
/
metrics.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
import numpy as np
from scipy import ndimage
def DSC(im1, im2):
"""
dice coefficient 2nt/na + nb.
"""
im1 = np.asarray(im1).astype(np.bool)
im2 = np.asarray(im2).astype(np.bool)
if im1.shape != im2.shape:
raise ValueError("Shape mismatch: im1 and im2 must have the same shape.")
im_sum = im1.sum() + im2.sum()
if im_sum == 0:
return empty_score
# Compute Dice coefficient
intersection = np.logical_and(im1, im2)
return 2. * intersection.sum() / im_sum
def vol_dif(im1, im2):
"""
absolute difference in volume
"""
im1 = np.asarray(im1).astype(np.bool)
im2 = np.asarray(im2).astype(np.bool)
if im1.shape != im2.shape:
raise ValueError("Shape mismatch: im1 and im2 must have the same shape.")
return np.abs(im2.sum() - im1.sum()) / im1.sum()
def rtpf(im1, im2):
"""
Regionwise True positive fraction
"""
pass
def ftpf(im1, im2):
"""
Regionwise True positive fraction
"""
pass