Last active
June 24, 2022 10:42
-
-
Save joonas-yoon/0586713e15b19295de9d9a1c33826bf0 to your computer and use it in GitHub Desktop.
This file contains 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
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