-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathutil.py
39 lines (31 loc) · 929 Bytes
/
util.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
import numpy as np
from skimage import color
import openslide
import os
import glob
###############
def isforeground(self, scan, xpos, ypos, level, mu_percent=0.1, thresh=0.75): # Mask Generation
wsi = scan.read_region((xpos, ypos), level, (self.tile_w, self.tile_h)).convert('RGB')
hsv = color.rgb2hsv(np.asarray(wsi))
hsv = hsv[..., 1] > mu_percent
return np.count_nonzero(hsv) / hsv.size >= thresh
###########
class AverageMeter(object):
"""Computes and stores the average and current value"""
def __init__(self):
self.val = 0
self.avg = 0
self.sum = 0
self.count = 0
self.reset()
def reset(self):
self.val = 0
self.avg = 0
self.sum = 0
self.count = 0
def update(self, val, n=1):
self.val = val
self.sum += val * n
self.count += n
self.avg = self.sum / self.count
#############