-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualize.py
36 lines (33 loc) · 1.21 KB
/
visualize.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
from numpy import stack, zeros, max, min
from matplotlib.pyplot import imsave, cm
from array2gif import write_gif
from skvideo.io import FFmpegWriter
def image_seq(grids, outfolder="out_gpu", cmap="jet"):
print("Generating image sequence...")
for i, grid in zip(range(len(grids)), grids):
imsave(outfolder + "/{:04d}.png".format(i),
grid.transpose(), cmap=cmap)
print("Images generated at " + outfolder)
def gif(grids, fps=25, outname="out_gpu"):
frames = []
print("Generating GIF sequence...")
for grid in grids:
grid[grid == 1] = 255
frames.append(
stack([zeros(grid.shape), grid,
zeros(grid.shape)], axis=2))
write_gif(frames, outname+".gif", fps=fps)
print("GIF created: " + outname + ".gif")
def mp4(grids, fps=25, outname="out_gpu"):
w = FFmpegWriter(outname + ".mp4", inputdict={"-r": str(fps)})
print("Generating MP4 video...")
for frame in grids:
mn, mx = min(frame), max(frame)
frame -= mn
frame /= (mx-mn)
frame = cm.jet(frame.transpose())
frame *= 255
frame = frame.astype("uint8")
w.writeFrame(frame)
w.close()
print("MP4 created: " + outname + ".mp4")