-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhelperfunctions.py
More file actions
28 lines (24 loc) · 1.04 KB
/
helperfunctions.py
File metadata and controls
28 lines (24 loc) · 1.04 KB
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
import numpy as np
import scipy.misc as misc
import scipy.ndimage as ndimage
def Beziercurve(points, t):
if len(points) == 2:
return points[0] * (1 - t) + points[1] * t
else:
intpoints = [Beziercurve([points[i], points[i + 1]], t) for i in range(len(points) - 1)]
return Beziercurve(intpoints, t)
def genvec(latent_dim = 16, lowerbound = -10, upperbound = 10, sidelen = 96, type="random", encoder=None, x_train=None):
if type == "random":
return np.random.uniform(lowerbound, upperbound, latent_dim)
else:
x = np.random.randint(0, x_train.shape[0])
z = encoder.predict(x_train[x].reshape((1, 1, sidelen, sidelen)))
return z
def process(frame, x, y, sidelen=96, threshold=128):
base = (frame * 255).reshape((sidelen, sidelen))
base = ndimage.gaussian_filter(base, sigma=1)
resized = misc.imresize(base, (x, y), interp='bicubic')
resized[resized < 128] = 0
resized[resized >= 128] = 255
#resized = resized[:, :, None].repeat(3, -1).astype("uint8")
return resized