Skip to content

Instantly share code, notes, and snippets.

@joonas-yoon
Last active June 24, 2022 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joonas-yoon/0586713e15b19295de9d9a1c33826bf0 to your computer and use it in GitHub Desktop.
Save joonas-yoon/0586713e15b19295de9d9a1c33826bf0 to your computer and use it in GitHub Desktop.
import os
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
from tqdm import tqdm
def file_list(path):
return list(map(lambda s: os.path.join(path, s), os.listdir(path)))
def plot_average_image(path):
a = file_list(path)
print(len(a), a[:5])
a_ = None
n = 1
for i in tqdm(a):
try:
img = Image.open(i, 'r').resize((228, 228))
except:
print('Wrong image file:', i)
continue
img = np.array(img)
if n == 1:
a_ = img
else:
a_ = ((a_ * n) + img) / (n + 1)
n += 1
del img
plt.imshow(a_ / 255.)
plt.axis('off')
plt.show()
del a_
del a
plot_average_image('../animeface/images')
plot_average_image('../celebA/img_align_celeba/img_align_celeba')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment