Unlocking Realistic Bokeh: Depth‑Aware Algorithms Behind Holiday Video Effects
This article explains the optical principles of bokeh (scatter blur), describes a depth‑aware variable‑focus algorithm developed by Kuaishou’s audio‑video team, and details practical optimizations such as saliency detection, edge‑preserving weighting, and adaptive spot‑light effects that enable realistic, customizable holiday video filters.
Bokeh Blur Principle
Common blur methods such as mean or Gaussian blur lack depth information and therefore cannot produce realistic bokeh. Bokeh blur, based on optical scatter blur principles, creates a depth‑of‑field effect that closely mimics professional camera equipment.
Optical Basis of Bokeh
Bokeh (also called out‑of‑focus rendering) is achieved by adjusting aperture and focal length so that regions outside the depth of field appear blurred, while the subject remains sharp. The size of the blur (circle of confusion) depends on aperture size, focal length, and subject distance.
The imaging formula of a lens relates object distance D , image distance V , and focal length F . When an object lies outside the focal plane, its light forms a blur circle rather than a point.
Depth Estimation and Saliency Detection
Since real‑world images lack explicit depth, the algorithm first estimates depth for each pixel and uses a lightweight saliency detection model to automatically locate the focus point. This provides a fast, accurate way to approximate object distance for subsequent blur calculations.
Depth‑Modulated Bokeh Algorithm
The blur weight for a pixel is computed from its depth relative to the focus depth, yielding a depth‑aware kernel. Unlike global Gaussian blur, this kernel varies with depth, producing realistic bokeh that respects the scene’s depth structure.
To avoid halo artifacts at edges, an edge‑preserving term reduces the weight of neighboring pixels whose depth differs significantly from the center pixel. An adaptive edge term further adjusts the weight based on the focus position (foreground vs. background).
Flexible Spot Effects
Spot effects are a special case of bokeh where additional weight terms are introduced:
Brightness weight: brighter pixels contribute more, shaping the spot.
Shape control weight: allows arbitrary spot shapes.
Breathing modulation: a sinusoidal function creates a pulsating light‑spot effect.
Real‑World Optimizations
Various practical enhancements improve visual quality:
Solid‑background detection adds seed spots to uniform backgrounds so that spot effects still appear.
Hollow‑spot overlap suppression uses non‑maximum suppression to reduce clutter from overlapping hollow spots.
Long‑strip spot suppression applies connected‑component analysis to prevent continuous spot streaks in bright linear regions.
Conclusion
The depth‑aware bokeh algorithm delivers realistic, variable‑focus blur with high export volume, making it suitable for holiday video templates and other creative video applications. Future work includes interactive refocusing and cinematic video effects.
References
Fernando, R. GPU Gems: Programming Techniques, Tips and Tricks for Real‑Time Graphics. Pearson Higher Education, 2004.
Haines, E., et al. Real‑Time Rendering, Fourth Edition, 2018.
Kuaishou Audio & Video Technology
Explore the stories behind Kuaishou's audio and video technology.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.