-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
48 lines (35 loc) · 923 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
42
43
44
45
46
47
48
import numpy as np
def stackLabels(imgs, labels):
result = []
for idx, item in enumerate(imgs):
result.append(_stackLabels(item,labels[idx]))
return np.stack(result)
def _stackLabels(img, labels, imgDim=128):
for l in labels:
label = l * np.ones([imgDim,imgDim])
img = np.dstack([img, label])
return img
def stackLabelsOnly(labels):
result = []
for label in labels:
result.append(_stackLabelsOnly(label))
return np.stack(result)
def _stackLabelsOnly(labels, imgDim=128):
result = []
for l in labels:
result.append(l * np.ones([imgDim,imgDim]))
return np.dstack(result)
def normalize(img):
img = img.astype('float64')
img = (img - img.min()) / (img.max() - img.min())
img = (img - 0.5) / 0.5
return img
def denormalize(img):
img = (img + 1) / 2
return np.clip(img, 0, 1)
def normalize2(img):
img = (img - 0.5) / 0.5
return img
def denormalize2(img):
img = (img + 1) / 2
return img