Stupidly simple depth from a single image

There’s a really simple trick for taking a picture and making it look like a miniature. Your eye has a pretty well-tuned depth-of-field detector, and it’s easy to trick it into thinking the image was taken at a different scale. Photographers have known this for a long time, and the old-school way of doing this is to exacerbate the depth-of-field effect by tilting the lens plane with respect to the film plane, like this (image from Wikipedia’s Motorrad-67):

Now, there is a simpler trick that also works pretty well. As a post-process, one can simply blur parts of the image that are closer or farther than a particular depth in the image. This is pretty effective. There’s a catch, however: notice that the people’s legs are at the same depth as their bodies, but blurred quite differently. Then the typical solution is to spend a lot of time creating a custom depth map, like described here.

I am, however, too lazy to draw my own depthmaps (and I probably couldn’t if I tried), and so I decided to code my way around this, and came up with a simple heuristic. A vertical gradient for depth almost works, and all you want to do is let the original gradient depth map “blur” in places where the image doesn’t change much. As it turns out, the cross-bilateral filter does exactly this: an edge-preserving blur of the intensities image A, using the edges of image B.

So, to compute a depthmap for your tiltshifted images, you simply run a cross-bilateral filter on a crude version of the depthmap (say, a vertical gradient) using the edges of your own image for a number of times, until it essentially converges.

To put it all together in code, you can get source code for the cross-bilateral filter at Sylvain Paris’ website, and you can use the open-source focus blur plugin for GIMP. And that’s how these came to be: Tiny Temple, Tiny Capitol.

Pretty cool for a night of hacking. Next project, Tiny Solitude.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s