Created
February 23, 2010 06:59
-
-
Save perimosocordiae/311953 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
import stereogram as s | |
import numpy as np | |
from sys import argv,exit | |
from os import system | |
from os.path import splitext | |
from PIL import Image,ImageSequence | |
# axis: 0 is up/down, 1 is left/right | |
def scroll_dmap(dmap,axis,amt): | |
return np.roll(dmap,amt,axis=axis) | |
def make_asg(dmap,patt_name): | |
return s.pattern_asg(dmap,s.pattern(patt_name,*dmap.shape)) | |
#return s.random_dot_asg(dmap) | |
def scrolling(num_frames): | |
dmap = s.displacement_map(argv[3]) | |
amt = dmap.shape[1]/num_frames | |
for i in range(num_frames): | |
asg = make_asg(dmap,argv[1]) | |
s.write_asg(asg,"asg-%03d.gif"%i) | |
#Image.fromarray(dmap,'L').save("asg-%03d.png"%i) | |
dmap = scroll_dmap(dmap,1,amt) | |
def oscillating(num_frames): | |
dmap = s.displacement_map(argv[3]) | |
first_half = range(num_frames/2) | |
for i in range(num_frames/4): | |
asg = make_asg(dmap,argv[1]) | |
s.write_asg(asg,"asg-%03d.gif"%i) | |
s.write_asg(asg,"asg-%03d.gif"%first_half[-i-1]) | |
#Image.fromarray(dmap,'L').save("asg-%03d.png"%i) | |
#Image.fromarray(dmap,'L').save("asg-%03d.png"%first_half[-i-1]) | |
dmap = scroll_dmap(dmap,1,-1) | |
dmap = scroll_dmap(s.displacement_map(argv[3]),1,1) # reset | |
sec_half = range(num_frames/2,num_frames) | |
for i in range(num_frames/4): | |
asg = make_asg(dmap,argv[1]) | |
s.write_asg(asg,"asg-%03d.gif"%sec_half[i]) | |
s.write_asg(asg,"asg-%03d.gif"%sec_half[-i-1]) | |
#Image.fromarray(dmap,'L').save("asg-%03d.png"%sec_half[i]) | |
#Image.fromarray(dmap,'L').save("asg-%03d.png"%sec_half[-i-1]) | |
dmap = scroll_dmap(dmap,1,1) | |
def from_gif(gif_name): | |
im = Image.open(gif_name) | |
for i,frame in enumerate(ImageSequence.Iterator(im)): | |
dmap = s.displacement_map_img(frame) | |
asg = make_asg(dmap, argv[1]) | |
s.write_asg(asg,"asg-%03d.gif"%i) | |
def from_images(): | |
for i,fname in enumerate(argv[3:-1]): | |
dmap = s.displacement_map(fname) | |
asg = make_asg(dmap, argv[1]) | |
s.write_asg(asg,"asg-%03d.png"%i) | |
if __name__ == "__main__": | |
if len(argv) < 4: | |
exit("Usage: %s pattern.img output.gif depth.img [...]"%argv[0]) | |
elif len(argv) == 4 and splitext(argv[3])[-1]==".gif": | |
from_gif(argv[3]) | |
elif len(argv) == 4: | |
oscillating(20) | |
else: | |
from_images() | |
print "stitching images..." | |
system("convert -delay 10 -loop 0 asg-*.gif %s"%argv[2]) | |
system("rm asg-*.gif") | |
print "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment