Skip to content

Bloom and glow

Fact Value
Also called Glow, Light bloom
Status Implemented and tested
Family Artistic and geometric effects
Engine Browser
Type Nonlinear, spatial, bright pass with blurred glow
Output Image
Operator shown as algorithm (exact)
Support radius floor(3 * sigma + 0.5)
Code web/src/core/filters/artistic/lens.ts, bloomFilter
Operator code web/src/core/filters/artistic/lens.ts, bloomPlanes

Overview

Bloom makes bright areas glow. Very bright light spreads a little in any lens and in the eye, so lights seem to shine past their edges. The filter blurs the bright part of the image and adds it back, in linear light.

Two panels: small colored lights on a dark blue background, and the same lights with soft glows around them. Two panels: small colored lights on a dark blue background, and the same lights with soft glows around them.
Small lights on a dark background, and the bloom with threshold 60, glow size 8 and strength 150.

How it works

  1. Decode the image to linear light.
  2. Keep the part of each pixel above the brightness threshold.
  3. Blur that part with a Gaussian.
  4. Add the blur back to the image and encode again.

Mathematical foundation

\[ B_c = c\, \operatorname{clamp}\left(\frac{Y - t}{1 - t}\right), \quad c' = c + k\, (G_\sigma * B_c), \qquad t = \frac{ 70 }{100},\ \sigma = 12,\ k = \frac{ 80 }{100} \]

The formula shows the default parameter values.

where

  • \(c\): A channel in linear light, from 0 to 1
  • \(Y\): The linear luminance
  • \(t, \sigma, k\): The threshold, the glow size and the strength

c is a channel in linear light and Y the linear luminance 0.2126 R + 0.7152 G + 0.0722 B. The bright part B keeps the share of the light above the threshold, rising linearly from 0 at t to all of it at 1. It is blurred with a Gaussian cut at 3 sigma and added back with the strength k. Light adds in linear space, so the glow mixes with the image as real light would. The results are clipped when encoded. The rule is PixelNexus's own.

Light adds linearly, so the glow is added to linear values. The bright part rises linearly from 0 at the threshold to the whole pixel at white, which avoids a hard edge where the glow starts. Spencer and colleagues model glare as light spread from bright sources over the image. This filter is a simple version of that idea.

Kernel or operator

The Inspector shows the steps of the effect as formulas with the current settings.

Algorithm

  1. Decode the image to linear light.
  2. Keep the bright part of each pixel, by how far its luminance is above the threshold.
  3. Blur the bright part with a Gaussian and add it back with the strength.
  4. Encode back to sRGB and clip.

Parameters

Parameter Default Values Meaning
Threshold threshold 70 0 to 100 % The linear luminance where the glow starts.
Glow size sigma 12 1 to 60 px The sigma of the Gaussian blur of the bright part.
Strength strength 80 0 to 300 % How much of the blurred light is added back.
Border mode border Reflect 101 (default) Reflect 101 (default), Reflect, Replicate, Constant (zero), Wrap How pixels outside the image are filled when the window reaches past the edge.

Implementation

bloomFilter in web/src/core/filters/artistic/lens.ts uses bloomPlanes.

Worked example

Distance from the white light 0 3 6 10 15 20
Red before 255 10 10 10 10 10
Red after 255 84 76 60 38 21

The red channel along the row through the white light of the figure, at x = 80 plus the distance. The light itself stays clipped at 255, and the glow lifts the dark background for some distance around it.

Complexity

  • Time: \(O(N r)\)
  • Memory: \(O(N)\)

N is the number of pixels and r the radius of the Gaussian, 3 sigma.

Artifacts and limitations

Limitations

  • Clipped highlights have lost their true brightness, so the glow can look weak.

Artifacts

  • A haze over the whole image at low thresholds.

Tests

The reference writes the bright pass, blur and sum again with NumPy and SciPy, and compares every output value on the test images of the fixtures. A unit test checks that strength 0 changes nothing.

References

  • Spencer, G., Shirley, P., Zimmerman, K. and Greenberg, D. P. Physically-based glare effects for digital images. SIGGRAPH 95, 325 to 334, 1995. DOI 10.1145/218380.218466.