Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Make video, demonstrating slit-scan photography
"""Make video, demonstrating slit-scan photography.
Sample is here: https://youtu.be/vz8gplAhDak
Both source and result videos are stored as sequences of PNG frames.
Source video must be in the current directory, frame names must have format 00001.png, 00002.png, ... etc.
Result video is stored in the 'output' folder, frame names having the same format.
Requirements: Python 2, PIL
Usage: run this script in the folder with soruce frames.
"""
from PIL import Image
import os
def process_frame( frame, current ):
assert( frame.size == current.size )
w, h = current.size
#scroll second part of the current by 1 pixel right.
center = w / 2
right_part = current.crop( (center-1, 0, w-1, h) )
current.paste( right_part, (center, 0) )
current.paste( frame.crop( (0, 0, center, h) ), (0, 0) )
def main():
cur_frame = None
cur_shape = None
idx = 1
while True:
fname = "%05d.png"%idx
if not os.path.exists(fname):
print "Stopped after processing %d images"%(idx-1)
break
img = Image.open(fname)
if cur_shape is None:
cur_shape = img.size
print "First image size: %s, mode: %s"%( cur_shape, img.mode )
cur_frame = Image.new( img.mode, cur_shape )
process_frame( img, cur_frame )
oname = "output/%05d.png"%(idx)
print "Saving frame %s"%(oname)
cur_frame.save( oname )
idx += 1
if __name__=="__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.