Created
August 15, 2016 11:00
-
-
Save Lukse/158c8ddad5c2f451812d4fafa08b7957 to your computer and use it in GitHub Desktop.
Stack images by using brightest pixel
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 os | |
| import fnmatch | |
| import numpy as np | |
| from PIL import Image | |
| from tqdm import trange | |
| images_in = "img" | |
| def find(directory, pattern): | |
| file_list = [] | |
| for root, dirs, files in os.walk(directory): | |
| for basename in files: | |
| if fnmatch.fnmatch(basename, pattern): | |
| filename = os.path.join(root, basename) | |
| file_list.append(filename) | |
| return file_list | |
| # Find pictures in specified directory | |
| imlist = find(images_in, '*.jpg') | |
| # take first picture as a refference | |
| w, h = Image.open(imlist[0]).size | |
| arr = np.zeros((h, w, 3), np.float) | |
| for j in trange(len(imlist), desc='Frames'): | |
| imgin = Image.open(imlist[j]) | |
| imarr = np.array(imgin, dtype=np.float) | |
| arr = np.maximum(arr, imarr) | |
| arr = np.array(np.round(arr), dtype=np.uint8) | |
| out = Image.fromarray(arr, mode="RGB") | |
| out.save("bri_"+images_in+".jpg") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment