Skip to content

Instantly share code, notes, and snippets.

@TimSC
Created February 21, 2018 20:44
Show Gist options
  • Save TimSC/6f5c72425e305c533f3eb107bea9bf92 to your computer and use it in GitHub Desktop.
Save TimSC/6f5c72425e305c533f3eb107bea9bf92 to your computer and use it in GitHub Desktop.
Calculate average image in python
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