Laplacian pyramid filtering¶
| Fact | Value |
|---|---|
| Also called | Laplacian pyramid, Band-pass pyramid, Multiscale detail enhancement |
| Status | Implemented and tested |
| Family | Wavelet and multiscale filters |
| Engine | Browser |
| Type | Linear, transform, band-pass decomposition and rebuild |
| Output | Image |
| Operator shown as | transform (exact) |
| Support radius | global |
| Code | web/src/core/filters/multiscale/pyramid.ts, laplacianPyramidFilter |
| Operator code | web/src/core/filters/multiscale/pyramid.ts, laplacianRebuild |
| Channels | RGB, Brightness only |
Overview¶
Laplacian pyramid filtering splits the image into detail levels of growing size and a small coarse image. Each detail level holds the detail that one REDUCE step removed. The filter multiplies the first four detail levels by their gains and adds everything back. Gains above 1 boost detail of that size, gains below 1 soften it, and gains of 1 give the image back exactly.
How it works¶
- Build a Gaussian pyramid with the chosen number of levels.
- For each level, expand the level above and subtract it. The difference is a detail level.
- Start with the top level of the Gaussian pyramid.
- Expand it, and add the detail level of that size times its gain.
- Repeat down to full size.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(G_k\): Level k of the Gaussian pyramid. G_0 is the image.
- \(L_k\): Detail level k of the Laplacian pyramid
- \(a_k\): The gain on detail level k. Levels above 4 keep gain 1.
- \(\hat{G}_k\): The rebuilt level k
- \(w\): The 5-tap kernel [1, 4, 6, 4, 1] / 16
- \(L\): The number of levels
G_0 is the image and G_{k+1} is level k reduced. REDUCE filters level k with the 5-tap kernel w along rows and columns. It keeps every second pixel, starting with the first, so a level of n pixels gives ceil(n / 2). EXPAND goes back up. Each output pixel sums the coarse pixels that land on it, weighted by 2 w(m) along each axis. So a flat level stays flat. Burt and Adelson define w by one number a, with w(0) = a, w(1) = 1/4 and w(2) = 1/4 - a/2. This filter uses a = 0.375, which gives the binomial weights [1, 4, 6, 4, 1] / 16. Each detail level L_k is a level minus the expanded level above it. So it holds the detail that the reduce step removed. Each band holds sizes about twice as large as the band before. The rebuild starts at the top level and adds the detail back one level at a time, each multiplied by its gain a_k. With all gains 1 the image comes back exactly. Gains above 1 boost detail of that size and gains below 1 soften it. The filter is linear, but not shift invariant.
A Gaussian pyramid holds the image at a series of sizes, each half as wide and half as tall as the one before. REDUCE blurs with a small kernel before it drops every second pixel. So most detail too fine for the smaller grid is removed first, which keeps aliasing low. EXPAND fills the dropped pixels back in by interpolation. Burt and Adelson chose the kernel w by a few rules. It is symmetric and adds up to 1. Also, every pixel of a level gives the same total weight to the level above. Burt and Adelson take the difference of each level and the expanded level above, the Laplacian pyramid. Each detail level is a band-pass image, about one octave of sizes. The rebuild reverses the subtraction, so with all gains 1 every step cancels and the image comes back exactly. A gain changes one band only, which makes the pyramid a simple tool to change detail by size.
Kernel or operator¶
The Inspector shows the stages of the pyramid as formulas. They are the REDUCE step with the kernel w = [1, 4, 6, 4, 1] / 16, the EXPAND step, and the number of levels. It also shows the detail levels L_k and the rebuild with the current gains.
Algorithm¶
- Set G_0 to the image.
- Reduce G_k to G_{k+1} for each level, with the border mode at the edges of each level.
- Take each detail level L_k as G_k minus the expansion of G_{k+1}.
- Start the rebuild with the top level G_L.
- For k from L - 1 down to 0, expand the rebuilt level and add a_k times L_k.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Levels levels |
4 | 1 to 8 levels | How many times the image is reduced. Each level halves the width and the height. The pyramid stops early when a level is one pixel. |
Gain, level 1 gain1 |
1 | 0 to 4 | The gain a_0 on L_0, the finest detail level. |
Gain, level 2 gain2 |
1 | 0 to 4 | The gain a_1 on L_1, detail about twice as large as in level 1. |
Gain, level 3 gain3 |
1 | 0 to 4 | The gain a_2 on L_2, detail about four times as large as in level 1. |
Gain, level 4 gain4 |
1 | 0 to 4 | The gain a_3 on L_3, detail about eight times as large as in level 1. Levels above 4 keep gain 1. |
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¶
laplacianPyramidFilter in web/src/core/filters/multiscale/pyramid.ts builds the levels with gaussianPyramid and rebuilds them with laplacianRebuild. Detail levels above the fourth keep gain 1. On a large image at low zoom, the preview runs on a smaller copy, and the number of levels drops by one for each halving of the size.
Worked example¶
| Gain 2 | Gain 1 = 1 | Gain 1 = 0.5 | Gain 1 = 0.25 | Gain 1 = 0 |
|---|---|---|---|---|
| 1 | 24.77 | 28.45 | 28.59 | 27.09 |
| 0.5 | 24.52 | 26.66 | 26.23 | 24.93 |
The PSNR in dB against the clean disks, for the disks with Gaussian noise of sigma 15, 24.77 dB before the filter. Gain 3 and gain 4 stay 1. Gains of 1 everywhere give the noisy image back. Lowering gain 1 to 0.5 or 0.25 removes much of the noise, since most of it sits in the finest level. Gain 1 at 0, or a lower gain 2, also takes away part of the edges of the disks, so the PSNR falls again.
Complexity¶
- Time: \(O(N)\)
- Memory: \(O(N)\)
N is the number of pixels. All levels together have about 4 N / 3 pixels.
Artifacts and limitations¶
Limitations
- Not shift invariant. The result depends on where the image falls in the pyramid grid.
- The bands overlap, so a gain also touches nearby sizes a little.
- The level sizes are fixed in steps of 2.
Artifacts
- Halos near strong edges when coarse gains are well above 1.
- Clipping at black and white when the gains raise detail past the 0 to 255 range.
Tests¶
The reference builds the same pyramid and rebuild with NumPy and covers three sets of gains and three border modes. More tests check that gains of 1 give the image back for all five border modes and that a flat image stays flat.
web/src/core/filters/filters.test.tsweb/src/core/filters/run.test.tsweb/src/core/filters/multiscale/multiscale.test.ts
References¶
- Burt, P. J. and Adelson, E. H. The Laplacian pyramid as a compact image code. IEEE Transactions on Communications 31(4), 532 to 540, 1983. DOI 10.1109/TCOM.1983.1095851.