Instantly share code, notes, and snippets.

What would you like to do?
Image Blender
# Mix rgb channels from subsequent images
from PIL import Image
import os, math, sys, random
fileList = os.listdir(".")
(width, height) =[0]).size
nPhotos = len(fileList)
offset = width/float(nPhotos)
dst ="RGB", (width, height))
for index, file in enumerate(fileList):
fileNum = index
rkeep, g, b =[fileNum]).split()
# Loop back to 0 if we've reached the end of the image sequence,
# Otherwise use the green channel from the next image in the sequence
if fileNum == (nPhotos - 1):
fileNum = 0
fileNum = fileNum + 1
r, gkeep, b =[fileNum]).split()
# Hack to make the flow more trivial - instead of looping around,
# We'll just use the second picture in the sequence for the second last
# And the first picture for the first
if fileNum >= (nPhotos - 1):
fileNum = nPhotos - fileNum
fileNum = fileNum + 1
r, g, bkeep =[fileNum]).split()
src = Image.merge("RGB", (rkeep, gkeep, bkeep))
box = (int(math.floor(offset*index)), 0, int(math.ceil(offset*(index+1))), height)
print "Cropping " + file + " coords: "
print box
dst.paste(src.crop(box), box)"teststaggeredrgb.jpg", "JPEG")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment