Vapoursynth HQDering

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

HQDering (HQDering mod, originally by mawen1250) removes ringing – the ripples next to sharp edges that compression or oversharpening leaves – by smoothing only a narrow area around the edges.

Filtering → Vapoursynth → DeRing

HQDering controls in Hybrid
HQDering controls in Hybrid

What it does

The picture is smoothed (MinBlur, or DFTTest with Noise radius 0), optionally sharpened again and repaired against the source, and the change is limited. A ring mask decides where this result is used: a Prewitt edge mask of the luma is thresholded, expanded and inflated, and the edges themselves are cut out again. Flat areas and the edges stay untouched, unless Edge is on.

Settings

Control Parameter Range / values Hybrid default Meaning
Radius mrad 0 – 100 1 Expands the edge mask; higher processes a wider area. 0 = no expansion.
Smooth msmooth 0 – 100 1 Inflates the mask and softens its borders. 0 = off.
Prewitt minp 0 – 100 1 Shrinks the inner edge mask that is left out; higher processes closer to the edges. Values above 3 act like 4. Only available while Edge is off.
Edge incedge on/off off Include the edges themselves in the ring mask.
Thresh mthr 1 – 100 60 Threshold of the edge mask (8-bit scale). Lower counts more pixels as edge and is more aggressive; with strong ringing a too low value protects the ringing as "edge".
Noise radius nrmode 0 – 3 2 Smoother: 0 = DFTTest, 1 – 3 = MinBlur radius (recommended 1 for SD, 2 for HD, 3 for UHD).
Sharpen sharp 0 – 3 1 Radius of the contra-sharpening after smoothing; 0 = off.
Repair mode drrep 0 – 24 24 Repair mode that keeps detail; recommended 24, 23, 13, 12 or 1; 0 = off.
Dither thr thr 0 – 128 12 Largest change (8-bit scale) that passes fully; limits darkening.
Dither elast elast 1 – 1000 2 Elasticity of the limit: changes between thr and thr × elast are blended in gradually.
Dither darkthr darkthr 0 – 128 3 Limit for brightening. Changing thr sets it to thr / 4; set it lower if lines suffer.
Planes planes all, chroma only, luma only, only U, only V, only Y,U, only Y,V luma only Planes that are processed; the mask always comes from luma.
Show show on/off off Shows the ring mask instead of the result; only in the preview, never in the encode.

Tools: Expr (akarin, cranexpr, std), DFTTest (neo_fft, dfttest2cpu, dfttest2, vszipcu, vsfeel; with Noise radius 0), RG (zsmooth, neo_smo; with Sharpen or Repair mode above 0), Median (zsmooth), EdgeMasks (edgemasks, std), Hysteresis (hysteresis, misc – Windows only).

Example

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

# deringing using HQDeringmod
clip = dering.HQDeringmod(clip, nrmode=2, darkthr=3.00, tools={'expr': 'akarin', 'dfttest': 'neo_fft', 'rg': 'zsmooth', 'median': 'zsmooth', 'edgemasks': 'edgemasks', 'hysteresis': 'hysteresis'})

How Hybrid calls it

  • HQDering works on 8–16-bit integer YUV clips; other formats are converted first.
  • Thresh, Dither thr and Dither darkthr stay on the 8-bit scale; the script scales them to the bit depth.
  • Noise radius and darkthr are always written, the other values only when they differ from the defaults.
  • With both thr and darkthr at 0 the change is not limited.
  • HQDering also offers the common options (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick).

Background

The script

HQDering mod v1.8 (2014) was part of havsfunc, the collection of AviSynth functions ported to VapourSynth; the current havsfunc no longer contains it. Hybrid's script collection carries the port on, with a Prewitt edge mask. When darkthr differs from thr, thr limits darkening and darkthr brightening.

Sources