The silver bullet for taking photos with a beautiful blurred background (Bokeh) are lenses with a wide aperture. These lenses are expensive, bulky, heavy and difficult to work with. By now blurred backgrounds obtained by postprocessing software cannot come up to the bokeh produced by an optical lens and there are few attempts to find a way out. In 2016 Thilo Gockel introduced the term Defocus Stacking for a manual method where he superposed a sharp image of the motif and one image with blurred background. It was a manual method requiring an exact mask of the motif and additional manual corrections.
This new approach is based on an image stack consisting of a sharp picture of the motif at the top and increasingly defocused images beneath. It does not require an exact mask for the motif, so we can use automatic segmentation algorithms and there is no need for manual corrections of the result.
Shooting a Defocus Stack
The new method is based on a stack of images: A sharp image of the motif constitutes the top layer and on the levels beneath we have images with increasingly defocused background. The recording workflow starts with a sharp image of the motif and for the following images the focus plane is moved towards the camera. In this way the file names generated by the camera can be used later to identify their level on the stack. The focus bracketing function implemented in some mirrorless cameras can be reversed and thus used to get a defocus stack.
How to shoot a defocus stack
The Defocus Stacking algorithm
The diagram below outlines the workflow of the algorithm: We have a Defocus Stack 1 with four levels: level 0 as the top level and level 3 as the lowest level.
- From the sharp image at level 0 a mask is generated isolating the motif from the The mask must not be very exact, therefore automatic segmentation algorithms can be used.
- The mask from step 2 is extended and blurred and used for blending the pictures on level 0 and level 1 of the
- The result from step 3 is shown as a purple symbol in this It becomes the new ‘foreground’ picture and is blended with the Image from level 2. The blending mask is obtained from step 3 , but enlarged and blurred for the blending operation. The result is used in the next step.
- We repeat this for all following levels of the In the diagram there is only one further step necessary for level 3.
- Finally we blend the image from level 0 with the result from the last step using the original mask. This integrates the sharp image from level 0 seamlessly into the blurred background from the last level of the
Schematic workflow of the Defocus Stacking algorithm
The process outlined above yields good results if the generated initial mask approximately isolates the motif and if the defocus steps between the levels of the stack are not too large. Because we extend and blur the mask from level to level we get a smooth transition from the sharp motif to the fully blurred background of the lowest stack level.
The segmentation algorithms
For getting the original mask the implementation of the algorithm as Photoshop action uses the Photoshop selection tools. The DefocusStacker implementation offers two well known automatic segmentation algorithms: “GrabCut” and “Connected Components”.
is the newer and more powerful algorithm. It uses a concept from graph theory published by Rother, Kolmogorov and Blake in 2012. All pixels of an image are arranged in a graph, where adjacent pixels are connected by edges. Each edge is weighted by the similarity of the two pixels at its vertices. Foreground and background pixels are separated by a graph theoretical method – a so-called ‘minimal cut’. It decomposes the graph into two parts – foreground and background – by cutting its edges so that the weight sum of the cut edges is minimal.
Principle of the GrabCut segmentation
identifies blobs in the picture, i.e. connected subareas with similar attributes such as the channels of the color space or the brightness. The DefocusStacker application implements the algorithm with only one attribute and by default it selects the largest blob as background. Our implementation allows to modify the assignment of the blobs to the foreground/background.
Defocus Stacking resultsPrinciple of the Connected Component segmentation
Defocus Stacking result for a motif with distinct edges:
Sharp picture and the GrabCut mask for the motif
Stack with four images and the Defocus Stacking result
Defocus Stacking sample for a motif with complex edges:
Sharp picture and GrabCut mask for the motif
Stack with five pictures and Defocus Stacking result
DefocusStacker is an implementation of the algorithm demonstrating the feasibility of the method. There are two versions:
- a Windows implementation (for Windows 10).
- a Photoshop action plus a jsx-script (tested with Photoshop CS5 and CC2021).
The references contain download links to both implementations and their user manuals.
User interface of the DefocusStacker application
Limitations of the method
Of course there are situations where the Defocus Stacking process can fail. One reason could be the number of images in the stack: Five to ten images are optimal in most situations. Too many images as well as too few images are counterproductive. Problems can also arise if the attributes of the motif and the attributes of the background are very similar so that the segmentation cannot separate them.
[H. Kopp] Defocus Stacking – Bokeh auch mit geringer Lichtstärke c’t Fotografie, Heft 6/2021
- DefocusStacker (msi-Installer for Windows10) https://www.dropbox.com/s/ucgvpf5yh33e1f2/DFS_Setup.zip?dl=0
- DefocusStacker (portable Version for Windows10) https://www.dropbox.com/s/94yt1cys9nznoi7/DFS_portable.zip?dl=0
- DefocusStacker(PS) (für Photoshop) https://www.dropbox.com/s/4h896z36wimsfcr/DefocusStacker%28PS%29.zip?dl=0