Deringing¶
| Fact | Value |
|---|---|
| Also called | Ringing removal, Mosquito noise removal |
| Status | Implemented and tested |
| Family | Restoration and reconstruction |
| Engine | Science engine |
| Type | Nonlinear, spatial, edge zone bilateral smoothing |
| Output | Image |
| Operator shown as | algorithm (exact) |
| Support radius | global |
| Code | engine/src/pixelnexus_engine/filters/artifacts.py, dering |
| Operator code | engine/src/pixelnexus_engine/filters/artifacts.py, dering_representation |
| Packages | OpenCV, SciPy |
| Channels | Brightness only, RGB |
Overview¶
Deringing removes the ripples that JPEG compression and strong sharpening leave next to strong edges, also called ringing or mosquito noise. It finds the strong edges, marks a narrow zone around them, and smooths that zone with a bilateral filter, which keeps the edge itself. The rest of the image stays untouched. The zone rule is PixelNexus's own. The filter runs in the PixelNexus engine on your computer.
How it works¶
- Smooth the luma with a Gaussian of sigma 1 and take its Sobel gradient, divided by 8.
- Mark the strong edges, where the gradient reaches the threshold.
- Widen them by the zone radius and blur the result into a soft weight.
- Smooth each channel with the bilateral filter and blend it in by that weight.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(Y\): The luma
- \(G_1\): A Gaussian of sigma 1
- \(E\): The strong edges
- \(D_r\): A disk of radius r, for the dilation
- \(w\): The blend weight of the zone, from 0 to 1
- \(\sigma_s, \sigma_r\): The space and range sigmas of the bilateral filter
Ringing is a ripple that compression and sharpening leave next to strong edges. It lives in a narrow zone around them, while flat areas and texture further away are fine. So the filter first finds strong edges. It smooths the luma with a Gaussian G_1 of sigma 1 and takes the Sobel gradient, divided by 8 to give levels per pixel. Edges are where it reaches the threshold T. It widens them with a disk D_r of radius r, and blurs the zone with G_1 again for a soft blend weight w. Inside the zone, a bilateral filter, after Tomasi and Manduchi, smooths the ripples but keeps the edge itself, since the edge differs by far more than the range sigma. The weights come from OpenCV's bilateral filter. The rule for the zone is PixelNexus's own.
Ringing comes from rounding away the high frequencies near an edge. The edge then overshoots and wiggles, like a sharp step drawn with too few waves. The wiggles stay close to the edge, within its 8 x 8 block for JPEG. So the filter works only there. Inside the zone, the bilateral filter of Tomasi and Manduchi averages each pixel with neighbors of similar value. The ripples are small, below the range sigma, so they average out. The edge is large, far above the range sigma, so its two sides are not mixed. The soft weight avoids a visible border at the edge of the zone. The rule for the zone is a simple heuristic of PixelNexus, not a model of the ringing, so the filter is labeled approximate.
Kernel or operator¶
The Inspector asks the engine for the stages with the current settings: the strong edges, the zone and the blend.
Algorithm¶
- Smooth the luma with a Gaussian of sigma 1 and take its Sobel gradient, divided by 8.
- Mark the strong edges where the gradient reaches the threshold.
- Widen them by the zone radius and blur the zone into a soft weight.
- Blend the bilateral filter of each channel with the channel by that weight.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Output output |
Cleaned image | Cleaned image, Zone | The cleaned image, or the blend weight of the zone, from black (kept) to white (smoothed). |
Edge threshold threshold |
20 | 1 to 200 | Strong edges are where the gradient of the smoothed luma reaches this many levels per pixel. |
Zone radius radius |
4 | 1 to 15 px | How far from a strong edge the smoothing reaches. Ringing of JPEG stays within its 8 x 8 block. |
Range sigma sigmaColor |
25 | 1 to 100 | The range sigma of the bilateral filter, in pixel values. Differences well above it are kept. |
Space sigma sigmaSpace |
2 | 0.5 to 6 px | The spatial sigma of the bilateral filter. Its window has a radius of ceil(2 sigma). |
Border mode border |
Reflect | Reflect 101 (default), Reflect, Replicate, Constant (zero), Wrap | How pixels outside the image are filled when the window reaches past the edge. |
Channels channelScope |
Brightness only | RGB, Brightness only | Which part of the color image the filter changes. |
Implementation¶
dering in engine/src/pixelnexus_engine/filters/artifacts.py builds the zone with edge_zone on the luma, then blends bilateral into each channel the scope names. The function bilateral extends the plane with the border mode and calls cv2.bilateralFilter of OpenCV with a window radius of ceil(2 sigma_s). There is no live preview. The result arrives when you click Apply.
Worked example¶
| Image | Quality | JPEG | Defaults | Range sigma 50 |
|---|---|---|---|---|
| Siemens star | 10 | 23.43 | 25.28 | 25.97 |
| Siemens star | 20 | 25.42 | 28.08 | 28.16 |
| Siemens star | 30 | 26.88 | 30.05 | 29.64 |
| Siemens star | 50 | 29.12 | 32.33 | 30.60 |
| Colored squares | 10 | 24.30 | 24.58 | 24.38 |
| Colored squares | 20 | 26.08 | 26.33 | 26.02 |
| Colored squares | 30 | 27.59 | 27.79 | 27.36 |
| Colored squares | 50 | 29.90 | 30.02 | 29.35 |
The PSNR in dB against the original, for images of 160 by 160 pixels saved with Pillow's JPEG encoder at each quality, without chroma subsampling, and decoded again. The deringing columns use the defaults, and then a range sigma of 50. The colored squares are the scene of the dehazing example. The Siemens star has many strong edges, where ringing is worst.
Complexity¶
- Time: \(O(N r_s^2)\)
- Memory: \(O(N)\)
N is the number of pixels and r_s the radius of the bilateral window. The other steps cost O(N).
Artifacts and limitations¶
Limitations
- Approximate. The zone rule is a simple heuristic of PixelNexus, not a model of the ringing.
- Fine texture next to strong edges is smoothed too.
Artifacts
- A soft band along strong edges in textured areas.
Tests¶
The test image is a step with ripples next to it. The zone must cover the edge and nothing far away. The ripples must drop by at least 3 dB, and pixels far from the edge must stay exactly. With a threshold above every edge, the image must stay exactly. The engine API tests run jobs and check the stages of the representation.
References¶
- Tomasi, C., and Manduchi, R. Bilateral filtering for gray and color images. Sixth International Conference on Computer Vision, 839 to 846, 1998. DOI 10.1109/ICCV.1998.710815.