Rendering Natural Camera Bokeh Effect with Deep Learning

Andrey Ignatov, Jagruti Patel, Radu Timofte

Abstract

Bokeh is an important artistic effect used to highlight the main object of interest on the photo by blurring all out-of-focus areas. While DSLR and system camera lenses can render this effect naturally, mobile cameras are unable to produce shallow depth-of-field photos due to a very small aperture diameter of their optics. Unlike the current solutions simulating bokeh by applying Gaussian blur to image background, in this paper we propose to learn a realistic shallow focus technique directly from the photos produced by DSLR cameras. For this, we present a large-scale bokeh dataset consisting of 5K shallow / wide depth-of-field image pairs captured using the Canon 7D DSLR with 50mm f/1.8 lenses. We use these images to train a deep learning model to reproduce a natural bokeh effect based on a single narrow-aperture image. The experimental results show that the proposed approach is able to render a plausible non-uniform bokeh even in case of complex input data with multiple objects.

Introduction

The aesthetic "portrait mode" look, characterized by a sharp subject against a creamy, blurred background, is a highly sought-after feature in mobile photography. This effect, known as bokeh, is naturally produced by DSLR cameras through large sensors and wide-aperture lenses. However, smartphone cameras are physically constrained by their small optics, resulting in a deep depth-of-field where most of the scene remains in focus.

Existing computational solutions often fall short, relying on simple Gaussian blurs that appear artificial or requiring specialized hardware like dual cameras and depth sensors. This research addresses the challenge of rendering realistic, lens-specific bokeh from a single standard image by learning the optical behavior of high-end lenses directly through deep learning.

Methodology: The PyNET Architecture

To achieve realistic bokeh, the researchers utilized PyNET, a convolutional neural network (CNN) with an inverted pyramidal structure. Unlike standard networks that process images at a single resolution, PyNET operates across seven distinct scales to capture both global context and fine-grained details.

The PyNET architecture featuring a multi-scale inverted pyramidal structure for processing images across seven different resolutions.

The network is trained sequentially, starting from the lowest resolution to learn global features like lighting and general blur areas, then moving to higher layers to reconstruct sharp edges and textures. The training process employs a combination of $L_1$ loss for pixel accuracy, Structural Similarity (SSIM) loss for luminance/contrast, and VGG-based perceptual loss to ensure visual fidelity. Interestingly, the researchers found that different levels of the architecture serve distinct functional roles: Level 7 manages global brightness and blur strength, while Level 3 defines the aesthetic texture of the bokeh.

The EBB! Dataset

A critical component of this work is the introduction of the EBB! (Everything is Better with Bokeh!) dataset. This large-scale dataset contains 10,000 images (5,000 aligned pairs) captured with a Canon 7D DSLR and a 50mm f/1.8 lens. For each scene, a pair of photos was taken: one at f/16 (narrow aperture, deep depth-of-field) to serve as the input, and one at f/1.8 (wide aperture, shallow depth-of-field) as the ground truth. The dataset covers a wide range of locations, weather conditions, and lighting setups to ensure the model generalizes well to real-world photography.

Experimental Results and Insights

The proposed approach focuses on learning the optical behavior of a specific lens rather than just scene geometry. This allows the model to reproduce subtle lens characteristics that traditional geometric models often miss. One significant finding was that traditional metrics like PSNR and SSIM are poor indicators of bokeh quality; consequently, the authors relied heavily on Mean Opinion Scores (MOS) from human testers.

Comparison of original images, bokeh effects rendered by PyNET, and ground truth photos from a Canon 7D DSLR.

Experimental results demonstrate that PyNET-rendered images are highly preferred by human testers. In a user study, the model's output was preferred over other state-of-the-art deep learning methods. Furthermore, when compared to the Google Pixel 2’s hardware-assisted "Portrait Mode," PyNET was preferred in 53.7% of cases, particularly in complex scenes where software-based disk blurs appeared unnatural. The model is also highly efficient, processing a 1024×1536 image in under 5 seconds on high-end mobile GPUs like the Snapdragon 855.

Conclusion and Future Work

While the system produces impressive results, approximately 5-8% of images still exhibit visible artifacts, particularly in areas where foreground and background objects share similar colors or have complex overlapping edges. Future research will focus on incorporating more accurate semantic information for better object separation and optimizing the architecture to handle full-resolution (12MP+) photos within mobile memory constraints. Additionally, the researchers plan to explore leveraging multi-camera setups to provide enhanced depth guidance to the PyNET model.

Summary updated

BibTeX
@inproceedings{ignatov2020rendering,
  author = {Andrey Ignatov and Jagruti Patel and Radu Timofte},
  title = {{Rendering Natural Camera Bokeh Effect with Deep Learning}},
  booktitle = {Workshops @ CVPR},
  year = {2020},
  url = {https://openreview.net/forum?id=jupBntgTuRX},
}
Figure