Last active
August 23, 2018 08:47
-
-
Save ishidur/c719fa91b0d6d2110a5f1c20387794a7 to your computer and use it in GitHub Desktop.
Pythonで画像からGIFを生成 #code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config | |
class GifMakerConfig: | |
__path = './results/' | |
__problem_set = 'random_30_cities/' | |
__en_path = 'elastic_nets/' | |
__som_path = 'self_organizing_map/' | |
source_dir = __path + __problem_set + __en_path |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from config import GifMakerConfig as Config | |
import matplotlib.pyplot as plt | |
import matplotlib.animation as animation | |
import glob | |
window_size = 5 | |
dpi = 150 | |
def sort_rule(x): | |
return int(x.split('-')[1].split('.')[0]) | |
if __name__ == "__main__": | |
source_dir = Config.source_dir | |
file_names = glob.glob(source_dir + "*.png") | |
file_names = sorted(file_names, key=sort_rule) | |
figsize = (window_size, window_size) | |
fig = plt.figure(figsize=figsize, dpi=dpi) | |
ax = plt.subplot(1, 1, 1) | |
ax.spines['right'].set_color('None') | |
ax.spines['top'].set_color('None') | |
ax.spines['left'].set_color('None') | |
ax.spines['bottom'].set_color('None') | |
ax.tick_params(axis='x', which='both', top='off', | |
bottom='off', labelbottom='off') | |
ax.tick_params(axis='y', which='both', left='off', | |
right='off', labelleft='off') | |
ims = [] | |
for file_name in file_names: | |
img = plt.imread(file_name) | |
im = plt.imshow(img, interpolation="spline36") | |
ims.append([im]) | |
ani = animation.ArtistAnimation(fig, ims) | |
# ani.save(source_dir + 'animation.gif', writer='imagemagick') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment