-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgif_plot.py
33 lines (30 loc) · 1.01 KB
/
gif_plot.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
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
import glob
import matplotlib.image as mpimg
import imageio
from ipdb import set_trace as st
import tqdm
import matplotlib
from PIL import Image, ImageDraw, ImageFont
matplotlib.use('Agg')
exp = 'exp73'
img_list = glob.glob(f'../adversarial-attack-ensemble/exp/{exp}/generated/generated-images-*.png')
# font = ImageFont.truetype("sans-serif.ttf", 16)
fig = plt.figure()
ims = []
Myfont = ImageFont.truetype('./cmb10.ttf',size=20)
(x, y) = (5, 5) # Text position
color = 'rgb(0, 0, 0)' # Text color
for ii,i in enumerate(img_list[::4]):
Srcimg = Image.open(i)
Drawimg = ImageDraw.Draw(Srcimg)
Mytext = str(ii)
Drawimg.text((x, y), Mytext, fill=color,font=Myfont)
Srcimg = np.array(Srcimg)
ims.append(Srcimg)
# ani = animation.ArtistAnimation(fig, ims, interval=200, repeat_delay=1000)
# ani.save("test.gif",writer='pillow')
imageio.mimsave(f'./gif/{exp}.gif', ims, duration = 0.01)
print(f"finished: {exp}")