Last active
December 5, 2016 02:40
-
-
Save hurutoriya/4dbb417a8de2b3ff08a3415e47eac8d6 to your computer and use it in GitHub Desktop.
Python Script for https://github.com/metalbubble/GKLT 1. make averageimage 2. make imgList.txt
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, numpy, PIL | |
from PIL import Image | |
def all_image_file_name(): | |
allfiles = os.listdir(os.getcwd()) | |
# discriminate the JPEG format | |
imlist = [filename for filename in allfiles if filename.split(".")[-1] in ["jpg", "jpeg", "JPG"]] | |
image_file_list = "\n".join(imlist) | |
f = open("imageList.txt","w") | |
f.write(image_file_list) | |
f.close() | |
def averageimage(): | |
# Access all PNG files in directory | |
allfiles = os.listdir(os.getcwd()) | |
# imlist[0].split(".")[-1] check file type only JPEG format | |
imlist = [filename for filename in allfiles if filename.split(".")[-1] in ["jpg", "jpeg", "JPG"]] | |
# Assuming number of all images over 5,000, for each 5 flame extract in all images. | |
imlist = imlist[::5] | |
# Assuming all images are the same size, get dimensions of first image | |
w, h = Image.open(imlist[0]).size | |
N = len(imlist) | |
# Create a numpy array of floats to store the average (assume RGB images) | |
arr = numpy.zeros((h, w, 3), numpy.float) | |
# Build up average pixel intensities, casting each image as an array of floats | |
for im in imlist: | |
imarr = numpy.array(Image.open(im), dtype=numpy.float) | |
arr = arr+imarr/N | |
# Round values in array and cast as 8-bit integer | |
arr = numpy.array(numpy.round(arr), dtype=numpy.uint8) | |
# Generate, save and preview final image | |
out = Image.fromarray(arr, mode="RGB") | |
# For top of the ImageList, We name to 0.jpg | |
out.save("0.jpg") | |
out.show() | |
if __name__ == "__main__": | |
# Make average image for GKLT. | |
averageimage() | |
# Create imageList.txt. | |
all_image_file_name() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment