Stereograms and anaglyphs

I’ve recently been working on various stereographics in preparation for the upcoming Summer exhibition (opening next Tuesday at Little Creatures). I’ve previously mentioned my love for stereographics, but I wanted to write a post with a bit more detail…

I’m technically inclined, mostly work in digital media, and advocate open source software. Accordingly, when trying to generate stereographics, I tried a bunch of open source programs and ended up writing a few small programs (python scripts) to solve problems I encountered.

The two main types of stereographics I’m interested in are anaglyphs (red/blue 3D images) and autostereograms (“magic eye” images). I also like crossed stereo pairs, since I find them relatively easy to view as 3D images.

Autostereograms are generally created from a depth map describing a particular viewpoint of a 3D scene, but other stereographics are usually created using a stereo pair of images (representing unique views from two “eyes”).

I wanted a stereographics creation process that was accessible to 2D artists, and drawing two unique views (and making sure that they match!) seemed like a very difficult task. However, I figured that many 2D artists would be able to draw greyscale depthmaps. So I went about writing a program to generate stereo pairs when provided with a depth map.

When looking for a depth map to test with, I immediately thought of Kazuki Takamatsu‘s work – which I’ve always wanted to see realised in 3D.

Here’s a sample (image resized and used without permission):

depth

Fabian Januszewski has written a neat autostereogram generator which is conveniently included in the Ubuntu package repositories. I used “stereograph” to generate a basic autostereogram of the above depth map:

stereogram

Generating stereo pairs (and an anaglyph) was a bit more work. There seemed to be heaps of programs that would generate a depth map given a stereo pair, but I couldn’t find anything that would generate a stereo pair from a depth map (the displace map in the GIMP seemed like it should work, but I couldn’t get it to…)

I knew that simply remapping the source depth map pixels to stereo images would result in gaps, but I was sure that a simple gap-filling algorithm could be used (rather than having to use splatting or other complex point cloud rendering techniques).

Here are the results of my first pass at stereo pair generation:

stereo

There are a few good guides (such as those by Gale Rhodes and Boris Starosta) on how to view cross stereo pairs such as the above image. (When you can see it in 3D, it’s pretty striking.)

One of the biggest problems I encountered with gap-filling was that anti-aliased edges represent erroneous depth data. If you imagine a depth map with a white line on a black background, the white line is near the camera and the black background is far away. When the line is anti-aliased, the grey pixels falsely imply that there are small dots floating somewhere between the (white) object and the (black) background.

Unfortunately, most of the depth maps that I found online “featured” anti-aliased edges. Fortunately, I should be able to disable anti-aliasing when generating my own depth maps. (Although this apparently isn’t an option when using Inkscape.)

The stereo pair looked good enough to attempt generating an anaglyph. I came across this GIMP script (by Steph Parker) which made it very easy to do. Here are the results (with the original depth map included along with the red and blue layers):

anaglyph

I’ve ordered some 3D glasses, but they haven’t yet arrived. So I’m not sure if the above image looks alright. (If you have a pair of red/blue 3D glasses, please let me know how the above image looks in 3D!)

After reading more about anaglyphs, I’d like to write a script that generates colour (rather than monochromatic) anaglyphs. It looks a bit more involved, but should be worth the effort.

I hope you enjoyed this write-up! No doubt I will post more about stereographics at some point in future. 😉