Multiresolution diffusion¶
| Fact | Value |
|---|---|
| Also called | Multigrid anisotropic diffusion, Pyramid diffusion, Coarse-to-fine diffusion |
| Status | Implemented and tested |
| Family | Wavelet and multiscale filters |
| Engine | Browser |
| Type | Nonlinear, iterative, coarse-to-fine anisotropic diffusion |
| Output | Image |
| Operator shown as | algorithm (exact) |
| Support radius | the whole image |
| Code | web/src/core/filters/multiscale/multires-diffusion.ts, multiresDiffusionFilter |
| Operator code | web/src/core/filters/multiscale/multires-diffusion.ts, multiresDiffusionFilter |
| Channels | RGB, Brightness only |
Overview¶
Anisotropic diffusion smooths flat areas and keeps edges, but each step moves information by only one pixel. Noise that forms wide blotches needs many steps before it goes. Multiresolution diffusion runs the diffusion on a Gaussian pyramid instead. A step at a level halved three times moves information by 8 pixels of the image. The coarse levels remove the wide blotches in a few steps, and each finer level refines the result near edges.
Definitions of multiresolution diffusion differ between papers. This is a documented variant of PixelNexus, close in idea to the multigrid anisotropic diffusion of Acton.
How it works¶
- Shrink the image a few times by half, with the Gaussian pyramid.
- Smooth the smallest copy with anisotropic diffusion, which keeps its edges.
- Enlarge the change that the smoothing made, add it to the next larger copy, and smooth that.
- Repeat up to the 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.
- \(u_k\): The diffused level k
- \(D\): A number of Perona-Malik steps
- \(g\): The conduction function with threshold K
- \(\nabla_d I\): The difference to the neighbor in direction d
- \(\lambda\): The step size
G_0 is the image and G_k its Gaussian pyramid. D is a number of Perona-Malik steps. Each step moves a value toward its four neighbors. The conduction g is near 1 for small differences and near 0 for large ones, so flat areas smooth and edges stay. The coarsest level is diffused first. The change it made is enlarged with EXPAND and added to the next finer level, which is diffused in turn. The result is u_0. This form is PixelNexus's own.
The change u_(k+1) - G_(k+1) carries the smoothing of a coarse level to the next one. Adding it to G_k, and not the coarse result itself, keeps the fine detail of G_k that the coarse level never had. The diffusion at level k then works from a start that is already smooth at large scales, so it only has to clean up near edges and fine structure.
Kernel or operator¶
There is no fixed kernel. The conduction depends on the local differences. The Inspector shows the pyramid and the steps with the current values.
Algorithm¶
- Build the Gaussian pyramid of the image.
- Diffuse the coarsest level.
- Going finer, enlarge the change of the level above, add it to the level, and diffuse.
- Write the finest level.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Levels levels |
3 | 0 to 6 | How many times the image is halved. 0 is plain Perona-Malik diffusion. |
Steps per level iterations |
10 | 1 to 50 | The diffusion steps at each level. |
Edge threshold K kappa |
20 | 1 to 100 | Differences much smaller than K are smoothed, much larger ones are kept as edges. |
Step size lambda lambda |
0.2 | 0.05 to 0.25 | How far each step moves. 0.25 is the largest stable step with four neighbors. |
Conduction conduction |
exp(-(d/K)^2), favors high-contrast edges | exp(-(d/K)^2), favors high-contrast edges, 1 / (1 + (d/K)^2), favors wide regions | The function that turns a difference into a conduction. |
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¶
multiresDiffusion in web/src/core/filters/multiscale/multires-diffusion.ts builds the pyramid with gaussianPyramid from the Gaussian pyramid filter and diffuses with diffuse from the anisotropic diffusion filter, so both parts are the tested code of those filters. Each diffusion repeats the edge of its level, the zero-flux boundary. The whole image is needed for the pyramid, so the filter runs on the whole image at once.
Worked example¶
| Method | PSNR (dB) |
|---|---|
| Blotchy noise | 26.19 |
| Perona-Malik, 10 steps (levels 0) | 28.74 |
| Perona-Malik, 40 steps (levels 0) | 31.45 |
| Multiresolution, 3 levels, 10 steps each | 32.41 |
PSNR against the clean Disks and dots test image, 96 x 96. The noise is Gaussian noise of sigma 60 on flat gray, blurred with a Gaussian of sigma 2, made 1.5 times stronger and added to the image. K = 20 and lambda = 0.2 everywhere.
The multiresolution result beats 40 plain steps, although its 40 steps are spread over four levels. The three coarse levels together cost less than one level of the full size.
Complexity¶
- Time: \(O(N n)\)
- Memory: \(O(N)\)
N is the number of pixels and n the steps per level. The coarser levels add a third of the work at most.
Artifacts and limitations¶
Limitations
- Low-contrast detail wider than a few pixels at a coarse level is smoothed away.
- The same K at every level, although differences are smaller at coarse levels.
Artifacts
- Slight blockiness from the pyramid where the coarse change is large.
Tests¶
A NumPy version in tools/fixtures_multires.py gives the reference for 0, 2 and 3 levels, both conduction functions and three border modes. It builds the pyramid with the checked reference of the Gaussian pyramid filter. Before it is used, the script checks its diffusion steps: with a huge K they must equal repeated convolution with the heat equation stencil in SciPy.
References¶
- Perona, P., and Malik, J. Scale-space and edge detection using anisotropic diffusion. IEEE Transactions on Pattern Analysis and Machine Intelligence 12(7), 629 to 639, 1990. DOI 10.1109/34.56205.
- Burt, P., and Adelson, E. The Laplacian pyramid as a compact image code. IEEE Transactions on Communications 31(4), 532 to 540, 1983. DOI 10.1109/TCOM.1983.1095851.
- Acton, S. T. Multigrid anisotropic diffusion. IEEE Transactions on Image Processing 7(3), 280 to 291, 1998. DOI 10.1109/83.661178.