Created
February 21, 2018 20:44
-
-
Save TimSC/6f5c72425e305c533f3eb107bea9bf92 to your computer and use it in GitHub Desktop.
Calculate average image in python
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 __future__ import print_function | |
import os | |
from scipy.misc import imread, imsave | |
import numpy as np | |
if __name__=="__main__": | |
total = None | |
fiLi = os.listdir(".") | |
for fi in fiLi: | |
fiSp = os.path.splitext(fi) | |
if fiSp[-1] != ".png": continue | |
img = np.array(imread(fi), dtype=np.float32) | |
if total is not None: | |
total += img | |
else: | |
total = img.copy() | |
total /= len(fiLi) | |
img = np.array(total, dtype=np.uint8) | |
print (total.shape) | |
imsave("out.jpg", img) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment