Last active
August 29, 2015 14:12
-
-
Save danmackinlay/e90846ac45aff78b83eb to your computer and use it in GitHub Desktop.
Dirty hack to fake long exposure from a quicktime movie
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 | |
import tempfile | |
import subprocess | |
import skimage | |
from skimage import exposure | |
import skimage.io as io | |
import argparse | |
import shutil | |
import numpy as np | |
for movfile in os.listdir("./"): | |
if not movfile.lower().endswith(".mov"): | |
continue | |
# movfile = "IMG_1318.MOV" | |
basechunk = os.path.splitext(movfile)[0] | |
# outdir = tempfile.mkdtemp() | |
outdir = basechunk | |
try: | |
os.mkdir(outdir) | |
except OSError, e: | |
pass | |
subprocess.check_call(["ffmpeg", "-i", movfile, os.path.join(outdir, "frame-%0d.png")]) | |
coll = io.ImageCollection( | |
os.path.join(outdir, "frame-*.png"), | |
conserve_memory=True, | |
load_func=lambda f: io.imread(f).astype(np.float32)) | |
# calculate an averaged frame | |
sumd = reduce(np.add, coll) | |
sumd = exposure.rescale_intensity(sumd) | |
io.imsave(basechunk+"_sum.png", sumd, ) | |
# create a frame made up of all the brightest pixels | |
maxd = reduce(np.maximum, coll) | |
maxd = exposure.rescale_intensity(maxd) | |
io.imsave(basechunk+"_max.png", maxd, ) | |
# Smush these two together in an arbitrary way to get some combination of brightness and detail | |
combd = sumd*3 + maxd | |
combd = exposure.rescale_intensity(combd) | |
io.imsave(basechunk+"_comb.png", combd, ) | |
shutil.rmtree(outdir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment