Bokeh Blur PDF
Bokeh Blur PDF
Abstract—This paper describes a recursive filter that space-variant IIR filters in artificial bokeh application. Section
handles discontinuous space-variant blur. The two-dimensional V summarises the main contributions of this works.
space-variant blur is approximated by separable Gaussian
filtering along the x- and y-dimensions. Within each dimension,
II. RECURSIVE GAUSSIAN FILTERS
the one-dimensional Gaussian filter is further approximated by
a pair of forward and backward Infinite Impulse Response (IIR)
filters applied in parallel. By modifying the blur sigma’s of the A. Infinite impulse response filters
IIR filters as they approach a blur discontinuity, smearing There are two types of filters used in digital signal
artefacts are eliminated. Different modifications of the forward processing: FIR and IIR filters. FIR filters are implemented as
and backward filter sigma’s results in an asymmetric space- a weighted average of the input samples. The set of weights or
variant IIR Gaussian filter. Our asymmetric IIR filters produce filter coefficients forms the impulse response of the filter. Due
visually pleasing background blur for a complicated scene to a finite number of filter coefficients, this type of filters has
whose contents are at different depths to the camera. a finite impulse response. The FIR filters are often
characterised by its filter coefficients. For examples, [0.25 0.5
Keywords—artificial bokeh, IIR filter, recursive filter, space- 0.25] is a 3-tap low-pass filter, and [-1 0 1] is a 3-tap central
variant filter
gradient filter.
= + + + (12)
− − − −
= −∞, … , ∞
= + + + (13)
a) cascaded filter [12] b) parallel filter [4] − − − −
= ∞, … , −∞
Figure 2: Two schemes of combining causal and anti-causal filters
= + (14)
where the filter coefficients nj, mj, and dj (j=1...4) are
1) Gaussian filter from second-order IIR filters derived from the function fit parameters ai, bi, ωi, and λi (i=1,2)
Deriche is the first to propose using two independent and the scale σ. Details of this derivation can be found in the
passes of IIR filters to approximate the Gaussian filter [4]. The original paper [5] and the author’s implementation in ITK1.
impulse response of the approximated filter is:
Figure 3 compares Deriche’s second-order IIR filter and
( ) = ( | | + 1) | | (3) Farnebäck’s fourth-order IIR filter with the Gaussian filter at
scale σ=10. The impulse response of the fourth-order filter
where = 5⁄(2√ ) and (red dotted line) closely matches the Gaussian function (green
thick line) within four standard deviation range (-4σ ≤ t ≤ 4σ).
(1 − ) (4) Root Mean Squared Error (RMSE) of the fourth-order filter
= against the Gaussian function is two orders of magnitude
1+2 −
smaller than the RMSE of the second-order filter.
This filter can be realised from a summation of a causal
and anti-causal IIR filter:
= + − − (5)
∀ = −∞, … , ∞
= + − − (6)
∀ = ∞, … , −∞
= + (7)
1
Function itkRecursiveGaussianImageFilter.txx in the Insight
Segmentation and Registration Toolkit (ITK) is available at
http://lmi.bwh.harvard.edu/~gunnar/itk_recursive_gaussian.html
-1
both causal and anti-causal directions at each pixel. While this
assumption is acceptable for slowly varying blur, it is not
0.05 10
15
=ℎ ( )
where h(s) = Ms + ε is a positive function of s with M>0 III. ASYMMETRIC SPACE-VARIANT RECURSIVE GAUSSIAN
and ε=0.001. Because σ is inversely proportional to α, the FILTER
space-variant blur is small close to edges and large in flat We propose an asymmetric space-variant recursive filter
image areas. To improve stability, Alvarez et al.’s solution to stop intensity leakage at blur discontinuities. Instead of
requires three cascaded filters for each pass over the signal having the same blur σ for both the causal and anti-causal pass,
(causal and anti-causal), two of which are second-order IIR filters in each direction get a different σ. For 2D images, where
filters. For 2D images, Alvarez et al. averaged two separable recursive filtering is applied in two directions (forward and
filter results: x followed by y and y followed by x to minimize backward) and separably in two dimensions (x and y), all four
the influence of filtering order. sigmas , , , can be different. As the sliding filter
approaches a blur discontinuity along its path, the blur width
1) Limitations of existing space-variant IIR filters
can be reduced to minimise intensity leakage from the other
Both Tan et al.’s [10] and Alvarez et al.’s filters [1]
assume locally isotropic blur because the same σ is used for
side of the discontinuity (this applies when σ changes abruptly
from low to high as in Figure 5a).
0
A. Constraining the rate of change of the directional
sigmas
0
B. Edge-stopping blur
c) flowers (green arrow in Figure 10, σcyan=2, σyellow=6, σred=10)
A prior art bokeh rendering method uses anisotropic
Input Deriche‘s 2- Farnebäck’s 4- Blur map and point diffusion to perform space-variant edge-stopping blur [2].
tap IIR filter tap IIR filter grid Diffusion-based approaches produce good edge-stopping
N/A 11.4 24.2 N/A bokeh but they have one disadvantage: slow speed due to their
iterative nature. The proposed asymmetric recursive Gaussian
Mip-map Our 2-tap Our 4-tap
interpolation asymmetric IIR asymmetric IIR
Our 2-tap filtering of filter can be used as a large-step speedup of anisotropic
the point grid
filtering filtering diffusion. The diffusivity parameter in anisotropic diffusion is
0.487 12.6 25.2
5.28 c=g(‖∇I‖), where g is a function that maps [0 +∞) gradient
magnitude ‖∇I‖ values to [1 0] output values such as
d) Image order and run-time on Matlab 2012 for a 2MP image (in seconds) g ∇ = exp (− ∇ / ). This diffusivity parameter can be
used to directly control the blur width of the space-variant
Gaussian filter. In the function mapping, k is a pre-determined
Figure 10: Zoom-in on the regions of interests in Figure 11. constant, for example, k=median(‖∇I‖) is the median of the
gradient magnitude of the image. An example of the space-
Figure 10d tabulates the run-times of different space- variant diffusivity c for the Lena image is given in the inset of
variant filters under investigation. The 2-tap filters are two- Figure 14b. The diffusivity is small (dark intensity) around
time faster than the 4-tap filters due fewer number of filtering edges in the scene, and large (bright intensity) in
taps. Our asymmetric IIR filters are slightly slower than prior homogeneous image areas. By setting the blur width to a linear
art’s symmetric IIR filters because four different directional multiplication of this diffusivity, e.g. σ=16×c, the result of the
sigmas have to be computed from the input blur sigma. asymmetric recursive Gaussian filter closely resembles the
Filtering on a grayscale grid-point image is also more than filtered result of anisotropic diffusion (see Figure 14). The
two-time faster than on a 3-channel RGB image. Note that the gradient measure ‖∇I‖ can be computed from the input
mip-map interpolation method is significantly faster than the image itself or it can be computed from a guide image.
IIR filters. This is because our implementation of the non- Typically, the guide image is in good alignment with the input
vectorisable IIR filters is in pure Matlab code. We expect a image to allow preserving the same edges in both images. The
significantly faster run-time of the IIR filters if implemented guide image could be in a different modality compared to the
in C. To illustrate this point, we used a C/MEX input image. For example, the input image and the guide
implementation of space-invariant IIR filter in Matlab image could be a non-flash/flash image pair, or a
(filter.m) to filter the same 2MP colour image with a fixed visible/infrared image pair.
blur sigma of 5.7 pixel (average of the space-variant sigma
used in Figure 11) and measured a run-time of 0.349 seconds.
This is even faster than our mip-map implementation. Because
the complexity of IIR filters is independent of the blur sigma,
we expect this run-time figure is extendable to our asymmetric
space-variant IIR filters.
Similar to most post-processing bokeh synthesis methods,
our asymmetric recursive filters require a good depth map for
a visually pleasing background blur. The depth discontinuities
should ideally coincide with edges in the scene. However, a
small misalignment of the depth image is acceptable as seen a) 20 iterations of Perona-Malik b) our edge-stopping blur with
in Figure 12d. Artefacts only become visible when the anisotropic diffusion with λ=0.25,
(‖∇ ‖) = exp(−‖∇ ‖/5) = 16 × exp(−‖∇ ‖)
misalignment of depth is significant compared to the size of
object of interest as in Figure 12f. This type of artefacts due to
depth map error can be alleviated using error concealment Figure 14: Anisotropic diffusion versus space-variant Gaussian blur.
[11].
A key differentiation of our space-variant recursive blur One potential drawback of approximating anisotropic
method over previous methods is also a cause of undesirable diffusion by a single iteration of separable Gaussian filtering
artefacts in certain bokeh synthesis cases. Because our filters in the X-direction followed by a single iteration of separable
completely block colour diffusion across depth Gaussian filtering in the Y-direction is directional dependent
discontinuities, background blur may not appears natural on artefacts for large blur width. Different orders of filtering (X
either side of a thin foreground structure. Figure 13 illustrates followed by Y or Y followed by X) result in slightly different
outputs. The discrepancy due to filtering order is more REFERENCES
pronounced for larger blur width. In order to reduce these [1] L. Alvarez, R. Deriche, and F. Santana, “Recursivity and PDE’s in
directional dependent artefacts, the desired blur can be image processing”, in Proc. of ICPR, pp. 242-248, 2000.
implemented with multiple passes of X- followed by Y- [2] M.Bertalmio, R.Fort, and D.Canchez-Crespo, “Real-time, accurate
filtering. Usually, 2 iterations of separable filtering are enough depth of field using anisotropic diffusion and programmable graphics
to reduce these artefacts to a negligible level. A 2D Gaussian cards”, in Proc. of 3DPVT, 2004.
filter with blur width σ can be implemented with two [3] P.J. Burt and E.H. Adelson, “The Laplacian pyramid as a compact
applications of a separable Gaussian filter with blur width image code”, IEEE Trans. on Communication 31(4): 532-540, 1983.
⁄√2. [4] R. Deriche, “Fast algorithms for low-level vision”, PAMI, 12(1): 78-
87, 1990.
[5] G. Farnebäck and C.-F. Westin, “Improving Deriche-style recursive
V. CONCLUSION AND FUTURE WORKS Gaussian filters”, Journal of Mathematical Imaging and Vision,
26:293-299, 2006.
We have presented a new algorithm for space-variant
[6] A.V. Oppenheim and R.W. Schafer, Discrete-Time Signal Processing,
Gaussian blur using edge-stopping recursive filters. The new 2nd Edition, Prentice Hall, 1999.
algorithm constrains the blur spread around blur [7] A.P. Pentland, “A new sense for depth of field”, PAMI, 9(4):523-531,
discontinuities to avoid colour bleeding across the 1987.
discontinuity. This is especially useful in artificial bokeh [8] P. Perona and J. Malik, “Scale-space and edge detection using
application where blur sigma can change abruptly across anisotropic diffusion”, PAMI, 12(7):629-639, 1990.
depth boundaries. [9] K. Schutte and G.M.P. van Kempen, “Optimal cache usage for
separable image processing algorithms on general purpose
Compared to existing IIR Gaussian filters, our asymmetric workstations”, Signal Processing, 59(1):113-122, 1997.
space-variant IIR Gaussian filters produce significantly less [10] S. Tan, J.L. Dale, and A. Johnston, “Performance of three recursive
artefacts at the cost of being slightly slower. algorithms for fast space-variant Gaussian filtering”, Real-Time
Imaging, 9:215-228, 2003.
For future works, we plan to re-implement our filtering [11] S. Webster, D. Katchalov, and T.Q. Pham, “Variable blend width
algorithm in C using OpenMP to fully utilise the parallel compositing”, US patent 9311901, filed on 27 June 2014.
processing cores in modern CPUs. We expect the C [12] I.T. Young and L.J. van Vliet, “Recursive implementation of the
implementation will deliver sub-second run-time for colour Gaussian filter”, Signal Processing, 44:139-151, 1995.
images at HDTV resolution (i.e. 2 mega-pixel RGB image).
a) 1442×1080 image with 2 depth planes (σred=0, σblue=10) b) synthesised background blur image using our 2-tap
filter
c) <4-pixel depth map mis- d) acceptable bokeh given e) depth map misalignment f) noticeable artefacts
alignment around the wig small depth boundary error around flower petals (~10 pixels) due to large depth error
Figure 13: Bokeh synthesis artefacts around thin foreground structures (2-pixel-thick hair strands).
a) input image with depth planes in false colour (σblue=0, σcyan=2, σgreen=4, σyellow=6, σpink=8 (spiky plant behind the
guitar), σred=10)