-
Notifications
You must be signed in to change notification settings - Fork 5
/
statscalc.py
83 lines (77 loc) · 3.94 KB
/
statscalc.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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 5 15:33:33 2018
Output the TP TN FP FN for a range of threshold covering all intensity difference
@author: syou
"""
import numpy as np
from utils import roc_score2, dsc, STAT
import h5py
from utils import num2str
import os
model = 'GMVAE' # or 'VanillaVAE'
sequential_number = 1
rhos = np.arange(20)/5.0
LGdata = h5py.File('% the data folder/BraTSLGG_data.hdf5', 'r') % load BRATSLGG dataset
LGlabel = h5py.File('% the data folder/BraTSLGG_label.hdf5', 'r') % and the groundtrue
HGdata = h5py.File('% the data folder/BraTSHGG_data.hdf5', 'r') % load BRATSLGG dataset
HGlabel = h5py.File('% the data folder/BraTSHGG_label.hdf5', 'r') % and the groundtrue
LGGindex = np.load('% the data folder/BraTSLGGindeces.npy') % number of each brain slices which are not pure background for BRATSLGG
HGGindex = np.load('% the data folder/BraTSHGGindeces.npy') % number of each brain slices which are not pure background for BRATSHGG
for rho in rhos:
for k in range(1):
LGGpath = '% the working folder' + model + '/BraTSLGG/Dataslicehe0.06FsTVRestoration' + num2str(sequential_number) +'/'+ "{0:.1f}".format(rho)
HGGpath = '% the working folder' + model + '/BraTSHGG/Dataslicehe0.06FsTVRestoration' + num2str(sequential_number) +'/'+ "{0:.1f}".format(rho)
savepath = os.path.join('% the working folder' + model + '/abs3statshe0.06FsTVRestoration' + num2str(sequential_number), "{0:.1f}".format(rho))
if not os.path.exists(savepath):
os.makedirs(savepath)
print 'calculating statistics for rho = ', rho
# print 'calculating statistics for step = ', k*50+49
LGrestore = h5py.File(LGGpath + '/restored_images.hdf5', 'r')
HGrestore = h5py.File(HGGpath + '/restored_images.hdf5', 'r')
print 'starting for LGG'
startind = 0
LGGauc = np.zeros(len(LGGindex))
LGGroc = []
LGGdsc = []
threshs = np.append(np.linspace(0,0.1,201),np.append(np.linspace(0.1,0.4,151)[1:],np.linspace(0.4,1,51)[1:])) #np.linspace(0, 1, 401)
LGsta = []
for i in range(len(LGGindex)):
nslice = LGGindex[i].astype(int)
endind = startind + nslice
LGmask = LGdata['Mask'][startind:endind,22:180,17:215].astype(bool)
pmask = LGlabel['Label'][startind:endind,22:180,17:215]
ori = LGdata['Test'][startind:endind,22:180,17:215]
restore = LGrestore['Restore'][startind:endind]
dif = -restore + ori
dif = dif[LGmask]
# print 'batch 99.9% intensity of dif for i = ', i, ' is ', np.percentile(dif,99.9)
dif = np.abs(dif)
print 'batch 99.9% intensity of abs dif for i = ', i, ' is ', np.percentile(dif,99.9)
pmask = pmask[LGmask] > 0
LGsta += [STAT(threshs, dif, pmask.astype(int))]
startind = endind
np.save(savepath + '/LGsta.npy', np.array(LGsta))
print 'starting for HGG'
startind = 0
HGGauc = np.zeros(len(HGGindex))
HGGroc = []
HGGdsc = []
HGsta = []
for i in range(len(HGGindex)):
nslice = HGGindex[i].astype(int)
endind = startind + nslice
HGmask = HGdata['Mask'][startind:endind,22:180,17:215].astype(bool)
pmask = HGlabel['Label'][startind:endind,22:180,17:215]
ori = HGdata['Test'][startind:endind,22:180,17:215]
restore = HGrestore['Restore'][startind:endind]
dif = -restore + ori
dif = dif[HGmask]
# print 'batch 99.9% intensity of dif for i = ', i, ' is ', np.percentile(dif,99.9)
dif = np.abs(dif)
print 'batch 99.9% intensity of abs dif for i = ', i, ' is ', np.percentile(dif,99)
pmask = pmask[HGmask] > 0
HGsta += [STAT(threshs, dif, pmask.astype(int))]
startind = endind
np.save(savepath + '/HGsta.npy', np.array(HGsta))