Skip to content

Instantly share code, notes, and snippets.

@danmackinlay
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danmackinlay/e90846ac45aff78b83eb to your computer and use it in GitHub Desktop.
Save danmackinlay/e90846ac45aff78b83eb to your computer and use it in GitHub Desktop.
Dirty hack to fake long exposure from a quicktime movie
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