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.
How it works¶
- Decode the image to linear light.
- Keep the part of each pixel above the brightness threshold.
- Blur that part with a Gaussian.
- Add the blur back to the image and encode again.
Mathematical foundation¶
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¶
- Decode the image to linear light.
- Keep the bright part of each pixel, by how far its luminance is above the threshold.
- Blur the bright part with a Gaussian and add it back with the strength.
- 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.
web/src/core/filters/filters.test.tsweb/src/core/filters/run.test.tsweb/src/core/filters/artistic/artistic.test.ts
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.