mean.py 549 B

12345678910111213141516171819202122
  1. import os
  2. import numpy as np
  3. from PIL import Image
  4. images = []
  5. for i, file_name in enumerate(os.listdir('./images')):
  6. if i % 10 == 0:
  7. print(i)
  8. path = './images/' + file_name
  9. image = Image.open(path)
  10. image_gray = image.convert('L')
  11. image_resize = image_gray.resize(size=(215,80))
  12. input_img = np.array(image_resize, dtype='int16')
  13. image.close()
  14. images.append(input_img)
  15. images = np.array(images)
  16. avg = np.mean(images, axis=0)
  17. img = Image.fromarray(avg.astype(np.uint8)).resize((215,80))
  18. img.save('mean.png')