Vapoursynth SMDegrain

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

SMDegrain is a general-purpose, purely temporal denoiser: it averages each block with the matching blocks of up to Temporal radius frames on each side, following the motion. It is a port of Dogway's SMDegrain 3.1.2d with optional features of the 4.x versions.

Filtering → Vapoursynth → DeGrain

SMDegrain controls in Hybrid
SMDegrain controls in Hybrid

What it does

  1. A search clip is made from the source: optionally prefiltered (Prefilter), brightened in dark areas (Str/Amp) and expanded to full range.
  2. Motion vectors are searched on that clip.
  3. The source is averaged along the vectors wherever the blocks match well enough (SAD); the prefilter only affects the search, never the output.
  4. Optionally: LFR restores the low frequencies where the vectors are unreliable, DCTFlicker calms flicker in that band, and Contrasharp sharpens the result.

Settings

Degraining

Control Parameter Range / values Hybrid default Meaning
Temporal radius tr 1 – 128 2 Frames on each side (mvtools: at most 6).
SAD / SAD-C thSAD, thSADC 1 – 64000 / 0 – 64000 300 / auto (0) Match thresholds for luma and chroma; auto = thSAD/2 (4.x formula with 4.x formulas).
Limit / Limit-C limit, limitc 1 – 255 255 / 255 Maximum change of a pixel on the 8-bit scale (255 = no limit).
Plane plane luma only, chroma U, chroma V, both chromas, all all Planes that are degrained.
Chroma chroma on/off on Use chroma in the motion search.
Contrasharp contrasharp -1 – 100 0 (off) -1 = ContraSharpening, above 0 LSFmod with this strength.
4.x formulas v4formulas on/off off Use the threshold formulas of SMDegrain 4.x.

Motion search

Control Parameter Range / values Hybrid default Meaning
Search search one time, nStep, logarithmic, exhaustive, hexagon, UMH, pure horizontal, pure vertical hexagon Search algorithm (ignored with mvgpu).
TrueMotion truemotion auto, SD, HD auto Truemotion presets; auto = on up to 1024×576.
MVglobal MVglobal auto, enable, disable auto Global motion; auto follows truemotion.
DCT dct 11 modes usual spatial blocks Block comparison (with mvutensils SAD or SATD).
Refine Motion RefineMotion 0 – 5 0 (off) Refinement passes, each halving the block size.
Blocksize blksize auto, 4 – 128 auto auto = 8 up to 1024×576, otherwise 16.
Overlap overlap auto, 2 – 64 (at most half the block size) auto Block overlap; auto = half the block size.
Padding (H/V) hpad, vpad auto, 4, 8, 16 auto Frame padding; auto = block size.
Pel pel auto, full-pixel, half-pixel, quarter-pixel auto Search precision; auto = half-pixel up to 1024×576, otherwise full-pixel.
SubPixel subpixel bilinear, bicubic, sharper Wiener, nnedi3 sharper Wiener Interpolation for subpixel search.
thSCD1 / thSCD2 thSCD1, thSCD2 0 – 16320 / 1 – 250 auto (0) / 130 Scene change thresholds; auto = 400 (4.x formula with 4.x formulas).

Search clip

Control Parameter Range / values Hybrid default Meaning
Prefilter prefilter off, light gauss blur, mild median/gauss blur, strong median/gauss blur, dfttest, KNLmeansCL, BM3D, DGDenoise off Denoiser for the search clip only.
Str / Amp Str, Amp 0 – 8 / 0 – 1 1.00 / 0.0625 Brightening of dark areas for the search (1 = none).
Range tv_range auto, limited, full auto Range of the source; auto from the frame properties.
LFR (Hz) LFR 0 – 3840 0 (off) Low Frequency Restore: cutoff frequency; restores large structures where the vectors are unreliable (300 is a typical value, below 50 acts as 50).
DCTFlicker DCTFlicker on/off off Calms flicker in the restored low frequencies; only with LFR.
Device device -1 – 16 -1 GPU for the DGDenoise prefilter and for GPU implementations chosen in the Tools group.

Tools: MV (mvutensils, mv, mvgpu), Expr, NNEDI3, DFTTest, NLMeans, BM3D, RG, Median and BoxBlur implementations; only the ones the chosen settings use are relevant.

Example

Default settings on a 10-bit YUV 4:2:0 source:

# removing grain using SMDegrain
clip = smdegrain.SMDegrain(clip, interlaced=False, tools={'mv': 'mvutensils', 'expr': 'akarin', 'nnedi3': 'znedi3', 'dfttest': 'neo_fft', 'nlmeans': 'nlm_ispc', 'bm3d': 'bm3d', 'rg': 'zsmooth', 'median': 'zsmooth', 'boxblur': 'vszip'})

How Hybrid calls it

  • SMDegrain works on 8–16-bit integer YUV and gray clips; float clips are converted first.
  • Interlaced material is processed as separated fields with vectors from same-parity fields and woven back; Hybrid passes the field order.
  • Values are only written when they differ from the defaults (Limit-C whenever it differs from Limit); the Tools choice is always written.
  • The Overlap list follows the block size, and DCTFlicker is only enabled with LFR.
  • SMDegrain also offers the common options (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick).

Background

The script

The VapourSynth version is a port of Dogway's SMDegrain 3.1.2d. The motion vectors come from a layer that supports mvutensils, mvtools and mvgpu, so any radius runs in one degrain call. LFR and DCTFlicker follow Dogway's 4.x implementation.

AviSynth (Dogway's SMDegrain 4.x)

Dogway's current AviSynth SMDegrain (4.7) is an MVTools2 wrapper with prefiltering, contra-sharpening and high-bit-depth handling. Its defaults and prefilter numbering differ from the 3.1.2d behavior used here (for example Str 5.0 and thSCD1 365), so its documentation applies only partly.

Sources