Tilt-shift blur¶
| Fact | Value |
|---|---|
| Also called | Miniature effect, Fake tilt-shift |
| Status | Implemented and tested |
| Family | Artistic and geometric effects |
| Engine | Browser |
| Type | Linear, spatial, position-dependent Gaussian blur |
| Output | Image |
| Operator shown as | algorithm (exact) |
| Support radius | global |
| Code | web/src/core/filters/artistic/lens.ts, tiltShiftFilter |
| Operator code | web/src/core/filters/artistic/lens.ts, tiltSigma |
| Channels | RGB, Brightness only |
Overview¶
Tilt-shift photos show a narrow band in focus with blur above and below. The eye reads such a shallow focus as a close-up of something small, so a street or a town looks like a model. This filter imitates the look with a blur that grows with the distance from a sharp band.
How it works¶
- Blur the image with Gaussians at nine sigmas, from 0 to the largest.
- Give each row a sigma from its distance to the sharp band.
- Blend the two blurred copies whose sigmas lie around the row's sigma.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(f, f_c\): The height of the row and of the focus center, as shares of the image
- \(b, w\): The half height of the sharp band and the transition
- \(\sigma_k\): The nine blur levels
- \(\lambda\): The blend weight of a row
f is the height of a row as a share of the image, f_c the focus center, b the half height of the sharp band and w the transition. Rows inside the band keep sigma 0. Outside it, sigma rises along a smoothstep to the largest blur. The image is blurred with Gaussians at nine sigmas, 0, 1/8 and so on up to the largest, each cut at 3 sigma. Each row blends the two blurred images whose sigmas lie around its own, with the weight lambda of its place between them. A real tilt-shift lens tilts its plane of focus. This filter only imitates the look, and its rule is PixelNexus's own.
A true blur that changes from row to row cannot be split into a row pass and a column pass, since each row would need its own column kernel. The stack of nine blur levels avoids that. Blending two levels is not exactly the Gaussian of the sigma between them, but the levels are close enough that the change looks smooth.
Kernel or operator¶
The Inspector shows the steps of the effect as formulas with the current settings.
Algorithm¶
- Blur the image with Gaussians at nine sigmas from 0 to the largest.
- For each row, compute its sigma from its distance to the sharp band.
- Blend the two blurred images whose sigmas lie around the row's sigma.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Focus center center |
50 | 0 to 100 % | The height of the middle of the sharp band, from the top. |
Sharp band band |
15 | 0 to 50 % | Half the height of the sharp band, as a share of the image height. |
Transition ramp |
25 | 0 to 100 % | How far, as a share of the image height, the blur takes to reach its largest value. |
Largest blur maxBlur |
6 | 0.5 to 30 px | The Gaussian sigma at the far ends. |
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. |
Channels channelScope |
RGB | RGB, Brightness only | Which part of the color image the filter changes. |
Implementation¶
tiltShiftFilter in web/src/core/filters/artistic/lens.ts uses tiltShiftPlane and tiltSigma. It is global, since the blur depends on the row's place in the whole image.
Worked example¶
| Row height f | 0 | 0.1 | 0.2 | 0.25 | 0.3 | 0.35 | 0.5 |
|---|---|---|---|---|---|---|---|
| sigma | 6 | 6 | 3.888 | 2.112 | 0.624 | 0 | 0 |
The blur sigma with the default settings: center 0.5, a sharp band of 0.15 on each side, a transition of 0.25 and a largest blur of 6. Rows from 0.35 to 0.65 stay sharp. The blur reaches 6 at a distance of 0.4 from the center, at f = 0.1 and above it.
Complexity¶
- Time: \(O(N r)\)
- Memory: \(O(9 N)\)
N is the number of pixels and r the radius of the largest Gaussian. Each of the nine blurs runs as two 1D passes.
Artifacts and limitations¶
Limitations
- The band is horizontal. Real tilt-shift lenses can tilt the plane of focus at any angle.
- The blur between two levels is a blend, not a true Gaussian of that sigma.
Artifacts
- Ghost edges where the blend of two levels mixes a sharp and a blurred copy of a strong edge.
Tests¶
The reference writes the blur stack and the blend again with NumPy and SciPy, and compares every output value on the test images of the fixtures. A unit test checks that the rows inside the band stay exactly as they were.
web/src/core/filters/filters.test.tsweb/src/core/filters/run.test.tsweb/src/core/filters/artistic/artistic.test.ts
References¶
- Potmesil, M. and Chakravarty, I. A lens and aperture camera model for synthetic image generation. ACM SIGGRAPH Computer Graphics, 297 to 305, 1981. DOI 10.1145/965161.806818.