by Alexander Thomas (aka Dr. Lex)
What is it?
AutoStereo2Depth is a command-line program that extracts depth (“3D”) information from autostereograms. It does this by searching for the best matching pairs of pixels within a certain range, and plotting a depth map based on their disparity. It is the inverse of programs that produce an autostereogram from depth maps (or 3D models) and a texture as input. It can also create an anaglyph from an autostereogram, which makes it much easier to view the depth by means of classic red/cyan 3D glasses, without the need to force your eyes into extremely unnatural focus/disparity combinations.
What is an autostereogram and why this program?
Autostereograms (ASGs) are 2D images that produce an illusion of depth when viewed in a special manner. The trick is to align your eyes such that your left and right eyes each look at a different point on the image, and if those two points correspond to the left and right views of the object in the image, your brain will give an illusion of depth. The problem is that not all people are able to exploit this trick. Obviously, this includes people who lack depth perception for physical reasons (e.g. pirates). But it also goes for people with perfectly working depth perception that rejects unnatural combinations of eye alignment and focus. I am one of those people: I cannot focus near if my eyes are aligned to look at something distant, which is exactly what is required for viewing ASGs. Believe me, I tried. I occasionally retry it and although I can now more easily align my eyes, focusing still fails.
My first attempt back in 2002 to see what's in an ASG, was manually performing a kind of ‘plane sweep’ algorithm in a graphics program. When horizontally sliding two copies of the ASG over each other in ‘subtract’ mode, dark areas will start to appear at matching disparities. By collecting these dark shapes and shading them according to the disparity, I could get a rough reconstruction of the shape. This was not just a tedious process to do manually, but it also introduces noise and is not very accurate as you can see in the result at the right.
So, the next step was to write a program that does basically the same but in a smarter way. It searches for each pixel the best match within a certain range (this is actually the easy part, obtaining the optimal search range is harder). The output is then shaded according to the best disparity for each pixel, and as you can see at the left, the output is smooth and clean. So, I could finally see what was in all the annoying ASGs I collected over the years. The popularity of autostereograms and stereo vision had completely dwindled in 2002 however, so the program stayed in a forgotten corner of my hard drive. With the recent revival of ‘3D’ (or more accurately stereo vision) thanks to Avatar etc, I suspected ASGs might also get a revival, therefore I cleaned up the code (which was from when I had only just learned C++), improved it, added more features and released the program in the public domain. This should help pirates as well as people with working stereo vision that doesn't let itself be easily fooled, get through the 2010 3D fad.
Compiling and using
The program is written in C++ and uses only standard libraries, plus a few image libraries of which only libJPEG is mandatory and libPNG and Magick++ are optional (this is rather arbitrary, it is trivial to adapt the source code to not require libJPEG). You need to compile it yourself. I don't provide precompiled binaries because I really don't have the time to provide support for a gazillion different architectures. If anyone feels like wrapping this into a neat Linux/OS X/Windows package with GUI, feel free. As you can see below, this program is released under the GPL. The easiest way to compile is to use CMake with the included CMakeLists.txt file. Or, you can manually tweak the included Makefile. Make sure to compile with at least optimisation level 2 (-O2), otherwise the program runs slow as a dog. Read the included INSTALL file for more details.
A self-explanatory help is included that is invoked with the ‘-h’ switch. AutoStereo2Depth can either automatically estimate the optimal disparity range, or you can enter your own parameters. The automatic detection is pretty good but for some ASGs, tweaking is required to obtain a perfect result. For anaglyph output (which is currently limited to red/cyan 3D glasses), the disparity can also be automatically set or manually tweaked.
The download includes an extended README as well as a sample autostereogram, courtesy of Wikipedia.
Mind that this program is not able to create autostereograms. I am not inclined to spend any time on adding that functionality, because I have no benefit from it. I reckon there must be gazillions of other programs that can generate autostereograms. Many of them might be ridiculously overpriced shareware, but some of them must be free, so just look around if that's what you're looking for.
AutoStereo2Depth is released under the GPL. This software is provided "as is", without any implied warranty or claim of fitness for a particular purpose. Use of this software is completely at your own risk.