Vignette¶
| Fact | Value |
|---|---|
| Also called | Vignetting, Edge darkening |
| Status | Implemented and tested |
| Family | Artistic and geometric effects |
| Engine | Browser |
| Type | Linear, spatial, radial gain |
| Output | Image |
| Operator shown as | algorithm (exact) |
| Support radius | global |
| Code | web/src/core/filters/artistic/effects.ts, vignetteFilter |
| Operator code | web/src/core/filters/artistic/effects.ts, vignetteFactor |
| Channels | RGB, Brightness only |
Overview¶
A vignette darkens an image toward its corners. Many lenses do this on their own, and photographers often add it on purpose to lead the eye to the center.
How it works¶
- Measure each pixel's distance from the center, with the corners at 1.
- Leave pixels closer than the start as they are.
- Beyond the start, darken them smoothly, down to the amount at the corners.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(d\): The distance from the center, 1 at the corners
- \(d_0\): The start
- \(a\): The amount
- \(f\): The factor on each pixel
d is the distance from the center of the image, measured on an ellipse with the shape of the image, so that the corners are at 1. Below the start d_0 nothing changes. Beyond it, the factor falls smoothly along the smoothstep curve t^2 (3 - 2t), down to 1 - a at the corners. This falloff is PixelNexus's own. Real lenses lose light toward the corners for several reasons, and their curves differ. With Linear light on, f multiplies the linear light values, as a loss of light does.
The smoothstep curve starts and ends flat, so there is no visible ring where the darkening begins or at the corners. In linear light, losing half the light lowers a gray of 200 to about 146, not to 100, because the sRGB encoding is not linear.
Kernel or operator¶
The Inspector shows the distance and the falloff with the current settings.
Algorithm¶
- Find each pixel's distance from the center, scaled so that the corners are at 1.
- Compute the factor from the start and the amount.
- Multiply the pixel by the factor, in linear light if it is on.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Amount amount |
50 | 0 to 100 % | How much light the corners lose. |
Start start |
50 | 0 to 100 % | Where the darkening starts, as a percent of the distance from the center to the corners. |
Linear light linearLight |
on | On or off | Scale the linear light values instead of the encoded values. |
Output mapping outputMapping |
Clip to 0 to 255 | Absolute value, Offset by 128, Stretch to full range, Clip to 0 to 255 | How signed results, such as gradients, become 8-bit pixel values. |
Channels channelScope |
RGB | RGB, Brightness only | Which part of the color image the filter changes. |
Implementation¶
vignetteFilter in web/src/core/filters/artistic/effects.ts multiplies each pixel by vignetteFactor. It is a global filter, because the factor depends on the position in the whole image.
Worked example¶
| Setting | d = 0 | d = 0.25 | d = 0.5 | d = 0.75 | d = 1 |
|---|---|---|---|---|---|
| Amount 50 %, start 50 % (defaults) | 200 | 200 | 200 | 176 | 146 |
| Amount 100 %, start 0 | 200 | 186 | 147 | 86 | 0 |
| Amount 50 %, start 50 %, encoded values | 200 | 200 | 200 | 151 | 100 |
A flat gray image of 200, 201 by 201 pixels, read along the diagonal from the center (d = 0) to the corner (d = 1). Below the start, nothing changes. In linear light, half the light is a level of about 146, not 100, so the corners look less dark than with encoded values.
Complexity¶
- Time: \(O(N)\)
- Memory: \(O(N)\)
N is the number of pixels.
Artifacts and limitations¶
Limitations
- The falloff is a simple smoothstep, not the measured curve of a real lens.
- Inside a selection, the center is still the center of the whole image.
Artifacts
- Banding in dark, smooth corners of 8-bit images.
Tests¶
The fixture cases compare every pixel with a NumPy version of the same falloff, in linear light and on encoded values. One case uses an amount of 100 and a start of 0.
References¶
- GIMP documentation, the Vignette filter, a similar effect with its own falloff. https://docs.gimp.org/2.10/en/gimp-filter-vignette.html