-
Notifications
You must be signed in to change notification settings - Fork 84
/
anim_gif_demo.py
30 lines (26 loc) · 1.02 KB
/
anim_gif_demo.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
'''
generate cool animation morphing effect for all digits
sampler is assumed to be an instance of Sampler()
'''
def create_z_array():
z_array = []
for i in range(10):
z_array.append(sampler.encode(sampler.get_random_specific_mnist(i)))
sampler.show_image_from_z(z_array[i])
return z_array
def make_img_data_array(z_array_input, sinusoid = True, fps=24, x_dim = 1080, y_dim = 1080):
z_array = list(z_array_input)
n = len(z_array)
data = []
for i in range(n-1):
print "Morphing Image #", i
sampler.show_image_from_z(z_array[i])
data.append(sampler.morph(z_array[i], z_array[i+1], fps, sinusoid = sinusoid, x_dim = x_dim, y_dim = y_dim))
sampler.show_image_from_z(z_array[n-1])
data.append(sampler.morph(z_array[n-1], z_array[0], fps, sinusoid = sinusoid, x_dim = x_dim, y_dim = y_dim))
return data
def write_data_array_as_gif(data_array, filename, fps = 24):
result = []
for i in range(len(data_array)):
result = result + data_array[i]
sampler.save_anim_gif(result, filename, 1.0 / float(fps))