Created
October 1, 2014 15:14
-
-
Save jplattel/2333b4fdecc741512155 to your computer and use it in GitHub Desktop.
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
import glob, numpy, PIL | |
from PIL import Image | |
# Access all JPG files in current directory, change this if neccesary | |
webcamshot_list=glob.glob('*.jpg') | |
# Assuming all images are the same size, get dimensions of first image | |
width,heigth = Image.open(webcamshot_list[0]).size | |
# Get the amount of files | |
webcamshot_count = len(webcamshot_list) | |
# Create a numpy array of floats to store the average (assume RGB images) | |
average_array = numpy.zeros((heigth,width,3),numpy.float) | |
# Build up average pixel intensities, casting each image as an array of floats | |
for webcamshot in webcamshot_list: | |
# print webcamshot # Print current webcamshot (for debugging) | |
webcamshot_array = numpy.array(Image.open(webcamshot),dtype=numpy.float) | |
average_array = average_array + webcamshot_array / webcamshot_count | |
# Round values in array and cast as 8-bit integer | |
average_array = numpy.array(numpy.round(average_array),dtype=numpy.uint8) | |
# Generate, save and preview final image as PNG | |
out = Image.fromarray(arr,mode="RGB") | |
out.save("average.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment