Skip to content

Instantly share code, notes, and snippets.

@godber
Last active August 29, 2015 14:08
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 godber/2beaccd01a4519e0c701 to your computer and use it in GitHub Desktop.
Save godber/2beaccd01a4519e0c701 to your computer and use it in GitHub Desktop.
Splits Red/Cyan Anaglyph into Left and Right Images and writes those images out into files with the same filename with '-left' or '-right' appended.
import os
from scipy import misc
def split_anaglyph_file(infile):
"""
Splits Red/Cyan Anaglyph into Left and Right Images and writes those images
out into files with the same filename with '-left' or '-right' appended.
"""
image = misc.imread(infile)
if len(image.shape) == 3:
h, w, b = image.shape
filename, extension = os.path.splitext(infile)
left_outfile = filename + "-left" + extension
right_outfile = filename + "-right" + extension
misc.imsave(left_outfile, image[:,:,0])
misc.imsave(right_outfile, image[:,:,1])
print "Images written: %s, %s" % (left_outfile, right_outfile)
else:
print 'WARNING: Input image does not have 3 bands: %s (skipped)' % infile
@godber
Copy link
Author

godber commented Nov 4, 2014

The choice of using image[:,:,1] was made arbitrarily, it could have been image[:,:,2], or perhaps it depends on how the anaglyph is made. This is for grayscale anaglyphs only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment