Local Laplacian filtering¶
| Fact | Value |
|---|---|
| Also called | Local Laplacian filter, Local Laplacian filters, Fast local Laplacian filter |
| Status | Implemented and tested |
| Family | Enhancement, illumination and color |
| Engine | Science engine |
| Type | Nonlinear, transform, edge-aware detail manipulation |
| Output | Image |
| Operator shown as | algorithm (approximation) |
| Support radius | global |
| Code | engine/src/pixelnexus_engine/filters/local_laplacian.py, local_laplacian |
| Operator code | engine/src/pixelnexus_engine/filters/local_laplacian.py, local_laplacian_representation |
| Packages | OpenCV |
Overview¶
Local Laplacian filtering, by Paris, Hasinoff and Kautz, raises or lowers fine detail without halos at strong edges. It can also compress the edges themselves. It works on a Laplacian pyramid, the stack of detail layers that the Laplacian pyramid page explains. The trick is that each coefficient comes from the image remapped around the local brightness at that place and scale. Small differences from it count as detail, and large ones as edges. PixelNexus computes it with the fast algorithm of Aubry et al. The filter runs in the PixelNexus engine.
How it works¶
- Take the intensity of the image and its color ratios.
- Build the Gaussian pyramid of the intensity.
- For each sampled value of g, remap the intensity around it and build its Laplacian pyramid.
- For each coefficient, interpolate between the two pyramids whose g values bracket the Gaussian pyramid value.
- Keep the coarsest level of the Gaussian pyramid, and collapse the pyramid.
- Put the color back with the ratios.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(r_g\): The remapping function around g
- \(g\): The Gaussian pyramid coefficient, the local brightness
- \(\sigma_r\): The largest difference that counts as detail
- \(\alpha\): The detail power
- \(\beta\): The edge factor
Paris et al. compute each coefficient of the output's Laplacian pyramid on its own. g is the value of the Gaussian pyramid at that place and level. They remap the image around g with r_g and copy the coefficient from the Laplacian pyramid of the remapped image. Differences from g up to sigma_r are details, scaled by f_d. Larger ones are edges, scaled by f_e. Because the remapping is centered on the local brightness, an edge stays an edge and makes no halo. To stop noise from growing when alpha is below 1, f_d blends back to x for differences under 1 to 2 percent of the largest intensity. Aubry et al. compute the remapped pyramids only for a few values of g and interpolate between them.
A plain Laplacian pyramid mixes detail and edges at every level. If you boost a level, you boost the edges in it too, and halos appear. Paris et al. avoid this with a remapping that depends on g, the local brightness from the Gaussian pyramid. Around g, values within sigma r are details and pass through f_d. Values further away are edges and pass through f_e. With f_e as the identity, an edge keeps its size, so the coefficient that describes it barely changes.
Done exactly, each coefficient needs its own remapped image and pyramid. Aubry et al. noticed that the remapping changes smoothly with g. So they remap the whole image for a few values of g and build one pyramid for each. Each coefficient is then interpolated between the two pyramids whose g values bracket the local one.
Kernel or operator¶
The pyramids use the 5 x 5 kernel of Burt and Adelson. The filter as a whole has no kernel. The Inspector asks the engine for the stages with the current settings.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Detail range sigma r sigmaR |
0.3 | 0.01 to 1 | Brightness differences up to this size, on a scale from 0 to 1, count as detail, and larger ones as edges. 0.3 as in Figure 7 of Paris et al. |
Detail power alpha alpha |
0.5 | 0.1 to 4 | The power of f_d(x) = x^alpha. Below 1, details grow, and above 1 they shrink. Our choice of 0.5. |
Edge factor beta beta |
1 | 0 to 2 | The factor of f_e(a) = beta a. Below 1, edges are compressed. Paris et al. use 1 for detail manipulation. |
Brightness samples samples |
16 | 4 to 64 | How many values of g the fast algorithm samples from 0 to 1. Our choice of 16. On a small test image it came within 39 dB of the exact algorithm. |
Implementation¶
local_laplacian in engine/src/pixelnexus_engine/filters/local_laplacian.py works on the intensity (20 R + 40 G + B) / 61 and keeps the color ratios, as Paris et al. do for tone manipulation. It builds the pyramids with OpenCV's pyrDown and pyrUp. The number of levels is floor(log2 of the shorter side) minus 2, our choice. The coarsest level, the low-pass residual, comes from the Gaussian pyramid of the intensity, also our choice. For alpha below 1, the paper blends f_d back to x for differences under 1 to 2 percent of the full range, to keep noise from growing. It calls this blend a smooth step without giving its shape. We use the cubic smoothstep.
Worked example¶
| Alpha | Beta | Texture, dark side (std) | Texture, bright side (std) | Step between the halves | Brightest pixel, bright side | Brightest pixel next to the edge |
|---|---|---|---|---|---|---|
| Input | 4.1 | 4.1 | 130.0 | 198 | 198 | |
| 0.25 | 1 | 18.3 | 16.9 | 128.5 | 213 | 210 |
| 0.5 | 1 | 11.2 | 10.1 | 129.4 | 207 | 204 |
| 1 | 1 | 4.1 | 4.1 | 130.0 | 198 | 198 |
| 2 | 1 | 0.8 | 0.8 | 129.9 | 192 | 192 |
| 4 | 1 | 0.4 | 0.4 | 129.7 | 190 | 189 |
| 1 | 0.3 | 4.8 | 4.8 | 123.5 | 198 | 182 |
The image of the figure, with sigma r 0.3 and 16 samples. The texture is measured in columns 16 to 63 and 96 to 143, and the step as the difference of their means. The last column is the brightest pixel in the 8 columns right of the edge, where a halo would show.
Alpha 0.25 makes the texture about four times stronger on both sides, while the step between the halves stays near 130. The brightest pixel next to the edge stays below the brightest pixel of the bright side, so no halo forms. Alpha 4 almost removes the texture and keeps the edge. Beta 0.3 changes the step only from 130 to 123.5. Most of a step this wide lives in the coarsest level, which the filter keeps as it is. So only the fine levels near the edge are compressed, which leaves a darker band right of the edge. Paris et al. compress edges this way on log intensities of HDR images, where large changes span many levels.
Complexity¶
- Time: \(O(K N)\)
- Memory: \(O(K N)\)
N is the number of pixels and K the number of brightness samples.
Artifacts and limitations¶
Limitations
- The fast algorithm approximates the exact one, which would be far slower.
- Strong detail boosts can bring out noise and compression artifacts, despite the guard against small differences.
Artifacts
- Grain in flat areas with a low alpha.
- Flat, cartoon-like areas with a high alpha.
Tests¶
The remapping must give the detail and edge values of the paper, leave differences under 1 percent alone when alpha is below 1, and be monotonic and continuous. The pyramid must collapse back to the image, and alpha 1 with beta 1 must leave the image as it is. On a small image, the fast algorithm must come within 30 dB of a direct version of Algorithm 1 with 8 samples, and within 35 dB with 16. On a textured step, a low alpha must raise the texture, a high alpha lower it, and no halo may pass the texture of the bright side. Beta below 1 must compress a step near the edge. The color ratios and the alpha must be kept.
References¶
- Paris, S., Hasinoff, S. W., and Kautz, J. Local Laplacian filters. Edge-aware image processing with a Laplacian pyramid. ACM Transactions on Graphics 30(4), article 68, 2011. DOI 10.1145/2010324.1964963.
- Aubry, M., Paris, S., Hasinoff, S. W., Kautz, J., and Durand, F. Fast local Laplacian filters. Theory and applications. ACM Transactions on Graphics 33(5), article 167, 2014. DOI 10.1145/2629645.
- 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.