Vapoursynth AntiRing

From wiki.selur.net
Jump to navigation Jump to search

AntiRing removes horizontal ringing: the faint echo lines left or right of a sharp vertical edge that sharpening or MPEG-2 compression leaves behind. It is a port of geometer's "Hans' Ringing Remover" for AviSynth+.

Filtering → Vapoursynth → DeRing

AntiRing controls in Hybrid
AntiRing controls in Hybrid

What it does

For each pixel the filter measures the edge strength in a small horizontal window, lowers that measure where real detail exists two and three pixels away (Protection 2/3), and turns the rest into a soft gate (Knee). Where the gate is open the pixel is pushed toward its neighbor at the chosen offset, with the chosen weight. Only horizontal neighbors are used, so the filter acts on vertical edges. The four modes differ in the number and placement of the correction lobes.

Settings

Control Parameter Range / values Hybrid default Meaning
Mode – LR, LR2, L2R2, 22LR 22LR LR: one lobe on each side. LR2: LR plus a weaker second lobe on the right, one pixel further out. L2R2: two lobes on each side. 22LR: like L2R2 with the main protection windows further out; tuned for NTSC DVD and recommended by the author.
Planes planes luma, chroma, all luma Planes that are filtered.
Weight L / Weight R weightL / weightR −1.5 – 1.5 0.25 / 0.25 Correction strength on the left / right side; 0 turns the side off, negative values invert the correction. Usual 0.15 – 0.7, with 22LR up to 1.5; larger offsets need larger weights.
Offset L / Offset R offsetL / offsetR 1 – 7 1 / 1 Distance from the edge to the echo in pixels (left / right). LR and LR2 use 1 – 3, L2R2 1 – 6; values above 3 are mainly for 22LR, where the correction weakens at large offsets.
Knee knee 0.01 – 2 0.7 Shape of the gate: low values give a soft transition, high values a more on/off behavior. Suggested 0.2 – 1.5.
Protection 2 / Protection 3 pr2 / pr3 0 – 1.5 0.5 / 0.5 Protection of fine detail two / three pixels from the edge; higher is less aggressive.
Tools: Expr – akarin, cranexpr, std akarin (std without AVX2) Expression backend; akarin needs a CPU with AVX2.

Example

Default settings on a 10-bit YUV 4:2:0 source (640x356):

# applying anti-ringing using AntiRing22LR
clip = dering.AntiRing22LR(clip, tools={'expr': 'akarin'})

How Hybrid calls it

  • AntiRing works on 8–16-bit integer YUV and gray clips; other formats are converted first.
  • The script works internally in 32-bit float, scaled so that all values behave as in the 8-bit original at every bit depth. Output format and frame properties equal the input.
  • Values are only written when they differ from the defaults; Hybrid's defaults are the script's defaults.
  • AntiRing also offers the common options (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick).

Background

The original

In the Doom9 thread the author names 22LR the newest and recommended variant: each side gets a positive and a negative lobe, and small text is protected better. The filter is aimed at DVD-resolution material, not at 4K; it works best on vertical edges and only partly on horizontal ringing. Interlaced material should be deinterlaced first. The author suggests upsampling (for example to 960×640) and 12 bit before filtering.

The port

The VapourSynth port always returns the input format; the AviSynth output parameter has no equivalent. Compared with the AviSynth original the difference is at most 1 code value, and planes that are not filtered stay bit-identical.

Sources