Understanding Defocus and Bokeh

What is Bokeh and how is it different from a simple “blur”?

What is Bokeh?

Defocus is basically blur, right? … Wrong. True defocus from even the most perfect lens has a very different look from gaussian blur and other common types of digital convolve based blurs. In this post we’ll explore the nuances. What is Bokeh and how is it different from a simple “blur”? Before we even go into a written description, let’s look at them visually. On the top is an idealized digital defocus with perfect circular bokeh. On the bottom is a simple blur. Both were applied to an HDR image with super-luminous spots of light. Can you see the difference?

Ok. Now that we’ve looked at a simple visual example, let’s dive into the details. Bokeh is a term used in photography to describe the aesthetic quality of the out-of-focus areas in an image. To put it another way, bokeh means “the quality/nature” of the defocus and not just “defocus” itself. When you take a photo, not everything is in sharp focus. The background or foreground may be blurry, and this photographic blur is what we call bokeh. Bokeh is often characterized by smooth and pleasing circles of light that result from the out-of-focus highlights in an image.

When we talk about the circles of light in bokeh, it's essential to understand that these circles are not always perfectly round. In fact, the shape of these out-of-focus highlights can reveal unique characteristics and imperfections of the lens being used. These imperfections contribute to the distinct personality of the bokeh in a photograph.

Lens aberrations, such as spherical aberration, coma, and astigmatism, can influence the shape and appearance of bokeh circles. Spherical aberration, for example, occurs when light rays passing through the edges and center of a lens converge at different points, causing a variation in focus. This can lead to bokeh circles with a soft or swirly effect, adding a touch of individuality to the image

Furthermore, different lenses may exhibit distinct bokeh characteristics. High-quality lenses with carefully designed optical elements tend to produce smoother and more uniform bokeh, creating pleasing, round circles. On the other hand, older or more budget-friendly lenses might introduce quirks in the bokeh, such as cat-eye shapes or more defined edges, especially towards the corners of the frame. Dust or internal imperfections in the lens might also leave a visually distinct patterns.

Photographers and Cinematographers often appreciate and even seek out these imperfections, as they contribute to the artistic and subjective nature of photography. The specific bokeh signature of a lens can become a distinctive feature of a photographer's work, adding a layer of uniqueness to their images.

As visual effects artists, it’s our job to replicate this “fingerprint” of the lens used to create a plate otherwise the elements we have added to a shot will not match the optical look of the plate.

Gaussian Blur

Gaussian blur, on the other hand, is a specific method of blurring used in image processing. Imagine you have a picture, and you want to make parts of it blurry. Gaussian blur does this by averaging the color values of pixels in a way that follows a Gaussian distribution (a specific mathematical curve). In simpler terms, it takes the color of a pixel and blends it with the colors of its neighboring pixels, creating a smooth transition from one color to another. This method is commonly used in graphic design and photo editing software to soften images or specific areas within an image.

The Difference

The key difference between bokeh and Gaussian blur lies in their purpose and how they are achieved. Bokeh is a naturally occurring blur in photography, resulting from the optical properties of the camera lens, particularly when using a wide aperture.

Gaussian blur, on the other hand, is a deliberate and controlled method used in post-processing to blur an image. Based on its algorithm is has a very different look from optical defocus. Gaussian blur still has it’s place for various purposes, for example, softening the edge of a matte or producing glows. But as we saw in our first visual example, Gaussian blur is too simple to match optical Bokeh in even the most simple case of a perfectly ideal lens. 

Even an ideal lens with what is often referred to as a “creamy” defocus will still produce the distinct circles of light associated with optical Bokeh.

Here is an example of a “creamy” photographic Bokeh in a real image from Unsplash. Notice how the background looks like a pretty smooth blur but the points of light still generate the circular features. The smoothness of the darker areas is actually produced by many overlapping circles. The points of light spread into larger circles as they have more energy. This is why we must operate in floating point HDR to get this effect in computer graphics. (We need the points of light to not be clipped in our working buffer.)

More “ideal” Bokeh.

Most lenses are not so perfect, however.  Here is an example of less perfect Bokeh, also from Unsplash.

Less “ideal” Bokeh. But if this is what the lens actually looks like you need to match it!

Bringing it all Together

How do we achieve matching these sorts of Bokeh in Nuke?   The answer is by using kernel. A kernel is basically just an image that describes the shape of the Bokeh. Both the ZDefocus and Convolve node have inputs for kernels (labeled “filter” on the input pipe). Feed them a 1:1 aspect ratio square image of of the Bokeh image you would like to achieve and that is what they will produce. In the case of the Convolve node, you will need to scale the filter image to control the size of the Bokeh it produces. You can have a lot of fun with this for stylized looks as the nodes will accept any shape as the kernel and produce some wild results (just as putting strangely shaped iris masks in an actual lens will do)

Using a hand drawn shape to define Bokeh in the convolve node. A sampled kernel could also be used!

The ZDefocus node will adjust the size of the Bokeh according to the settings you provide regarding depth and defocus.

Using a sampled kernel in the ZDefocus node. You’d use the ZDefocus if you had a z channel defining the z-dpeth in your plate. (Don’t forget you can make a synthetic z channel with roto shapes or or a Cattery model also!)

So, where do you get a natural looking Bokeh kernel? Well, if you are lucky, you can often just crop one out of an image you know was shot by the lens you are trying to match. On a larger film or series project, the VFX supervisor may have requested that the lenses being used by the show be profiled to capture reference images of the Bokeh. You can also sample them from any photo that has a bokeh you like.

Bokeh kernel cropped from above example photo. A little low res but good enough if we are just trying to match bokeh of this same size.

Sr. Compositor Josh Parks recently published a set of lens kernels for FREE you can download to experiment with. Here is a link. https://www.compositingpro.com/free-lens-kernels 

This is a fantastic resource. With a large collection of kernels like this you can often find one that produces a look that matches the lens you are trying to match. (Don’t forget you can edit the kernels and mix them together if needed to help create a match also!) Consider giving Josh a follow if you don’t follow him already.

Going the Extra Mile

Even when you aren’t trying to match a specific Bokeh, a more natural looking / organic Bokeh can help spice up your images. For example, if you are creating pure C.G. images or simply want to spice up the defocus in images from a more simple camera system you are comping elements from… adding natural looking Bokeh, chromatic aberration and other natural optical defects can help break the sterile look of the C.G. and help it feel more organic. 

While I think this post might be enough to point you in the right direction, if you’d like me to do a video that goes into more detail for how to set up Bokeh, please respond to this survey.

Should I create a video where we dive into Defocus and Bokeh in Nuke a bit deeper?

Login or Subscribe to participate in polls.