Here’s a tutorial on how you can create fake depth of field blur in the background of photos using something known as “Z-Depth Pass.” I’m not saying that this technique is better than other methods — because it has some problems — but it’s quite different, and some of you may learn something new.
Z-Depth Pass is a very old technique that is used in the composting of 3D computer graphics. Basically, it lets you render 3D scenes without depth of field blur, and then add depth of field as part of post-processing.
Scenes are usually rendered in multiple passes, like beauty pass, reflection pass, shadow pass, z-depth pass, etc… Here’s an example in which I rendered beauty pass (base layer):
…and then z-depth pass. It is simple grayscale image that maps depth information of individual pixels. The further a pixel is from the camera the darker it is and vice versa.
Most compositing software has tools to create fake depth of field from Z-Depth Pass. It is even possible to animate depth of field shift from still frames like in light field photography.
Now, seeing how Z-Depth Pass is used, you don’t have to be rocket scientist to figure out that it’s possible to do the same thing with still photographs in Photoshop. Here’s how you can do so…
First, you will need a base image. It is important to have as sharp and big an image as possible.
Add a gradient to represent the “base” of the scene. This can be a floor, a wall, etc… but in my case it’s a bar counter.
Next, add a layer mask to cut out the bar counter from the background. To make it easier, I decreased the gradient opacity of this layer.
After the base is done, I created new layer and masked out the letters. In this case, I needed only one layer, but in many cases, it is necessary to create a separate layer for each object.
The easiest technique to paint correct depth information for each object is to sample the color of the base gradient where the object is touching the base. Then, using this color, paint in the object. In my case, I used the Clone Stamp tool to sample the base and paint in all the letters.
In this next image, you can see the finished letters:
To finish up, I created a background and then painted it in the same color as the furthest part of the bar counter. All I had to do now, to finish this z-depth pass, is to collapse it into single layer.
To make it possible to blur the image, we need to create layer mask for the photograph and then copy z-depth pass to it.
When the most tedious part of this process is done, let’s get to the fun part! Open Filter->Blur->Lens Blur. A new window with the Lens Blur tool will pop up. To use the z-depth layer you created, change Depth Map Source to Layer Mask.
Now, you can tweak the blur amount and look with the Iris parameters. To focus on a specific area, you can left-click on desired point on image, or play around with Blur Focal Distance slider.
After you finish up Lens Blur tool, delete the layer mask with z-depth. And voila!
Here’s a before-and-after comparison:
Here is a quick time-lapse, through the entire process:
Now let’s talk about disadvantages and issues with this technique. Like I mentioned in the beginning, this technique requires really sharp and large images. This is because the object masks need to be as sharp as possible and they have to overlap perfectly with photograph. This can be quite a tedious process. Although I used the Brush tool for masking, it’s better to use the Pencil tool, without anti-aliasing, to have even sharper results.
Next, even with a perfectly sharp and aligned z-depth pass, you will still encounter some artifacts around the edges of objects. This can be corrected by blurring these edges with Blur brush after applying Lens Blur tool.
That is pretty much it! I hope you enjoyed this tutorial.