Skip to content
March 11, 2008 / cdsmith

Just For Fun: Autostereograms in Haskell

I’ve added some code here, which I wrote last night, to generate autostereograms from depth maps. It’s written in Haskell, but that doesn’t mean you should blame Haskell for its shortcomings.

To use:

  1. Install GHC and gtk2hs. Any recent version should do.
  2. Copy this code into a file and build with ghc --make -O2 TheFile.hs.
  3. Generate a tiling background image of your choice. GIMP’s Filter -> Map -> Make Seamless helps a lot with this, and it has some nice options under Filter -> Render to generate nice-looking images. The important thing is for your image to be seamlessly tileable, and have lots of easily identifiable points. Save it as a PNG file.
  4. Generate a depth map, on the order of about 100 x 100 pixels. (Too much larger, and you’ll have to profile and optimize my code for me.) Save it as a PNG file again.
  5. Run the program with the depth map and the background image (in that order) as parameters.

This code basically works, and realistically that’s about all I am going to do right now. There are lots of things that could be improved about it. The big three are: lots of performance issues; should be able to write out to a file instead of just the screen; and there’s something funky in the drawing that causes the depth to slope outward rather gently to each side no matter what the depth map looks like. As far as performance, the problem is with a lot of fiddling with lists for control flow; I was able to do considerably better with Cairo; but unfortunately, Cairo’s matrices only allow for affine transformations, which doesn’t seem to be quite enough to scale between arbitrary trapezoids, so the result didn’t look great and I reverted to drawing pixel by pixel. The last problem may be a rather fundamental issue in how I’m approaching the problem; but the current code works well enough to get the point.

Here are some obligatory screen shots.

Autostereogram of a LambdaAutostereogram of a Chess BoardAutostereogram of a Human


Leave a Comment
  1. Porges / Mar 11 2008 4:54 pm

    Super cool! :)

    What is the second one supposed to be? I can’t see anything vaguely related to chess in it :P

  2. Axio / Mar 12 2008 6:57 pm

    The second one isn’t clear to me either. I tried both convergent and divergent methods without being able to tell out…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: