In this tutorial, we explore ways to fake Depth of Field for a 2D image. If you have created a depth map from your footage or if you are working with 3D rendered images and have a z-channel available, then you can use that depth information to control the depth blur.
However, not all blur effects are created equal and artifacts can occur. The simplest option is to use the depth map as a mask on a regular blur. This will mix the blurred image with its original as per the mask. This is not an accurate way of representing depth blur and the result can be inconsistent. The same logic applies to every other blur tool (Lensblur, Defocus) that you could adjust with a regular mask input.
A better approach is to use a VariBlur node, which can adjust the blur radius based on the depth information, thus applying a larger blur in the background compared to the foreground. Both the masked blur and the Variblur however can create artifacts around foreground edges. The problem is that the larger blur on the background includes foreground pixels in the blur computation.
The ideal solution is a tool that separates pixels from foreground and background and ensures that foreground pixels don’t impact the blur in the background. One tool that can achieve this out of the box is the Frischluft Lenscare Depth of Field OFX plugin.
For some simple scenarios, you can do a hard foreground/background separation and blur both layers individually. For this, you can cut out the foreground from the background (garbage mask on MatteControl), then extend edges into the transparent areas of the background (Clean Plate), and apply the preferred blur tool on top of that.
3D Scene in this video: Winter Castle Knight by fdoss001, CC-0 license, https://blendswap.com/blend/24418