Avisynth SMDegrain

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

SMDegrain is a general-purpose temporal denoiser built on the MDegrain function of MVTools. It averages each block with the matching blocks of up to Temporal radius frames on each side, following the motion, and can give some sharpness back afterwards.

Filtering → Avisynth → DeGrain

SMDegrain controls in Hybrid
SMDegrain controls in Hybrid

What it does

  1. A search clip is made from the source. It can be prefiltered (Prefilter) and brightened in dark areas (Str and Amp), because motion search works better on a calm, bright picture.
  2. Motion vectors are searched on that clip.
  3. The real clip is averaged along the vectors wherever the blocks match well enough (SAD). The prefilter only affects the search, never the output.
  4. Optionally Contrasharp sharpens the result a little to compensate for the softening.

Typical use: grainy or noisy footage. A higher Temporal radius denoises more but is slower and can cause ghosting around fast motion. Interlaced material is handled by processing the fields separately.

Requirements

Windows, CPU only. The plugins and scripts needed are shipped with Hybrid. The KNLmeansCL prefilter needs OpenCL.

Settings

Degraining

Control Parameter Range / values Hybrid default Meaning
Temporal radius tr 1–128 2 Number of frames on each side. Higher is stronger and slower. Up to 6 MDegrain1–6 is used, above that MDegrainN.
SAD / -C thSAD / thSADC 1–64000 300 / 150 Block match thresholds for luma and chroma. Blocks above the threshold get less weight.
Limit / -C limit / limitc 1–255 255 / 255 Maximum change per pixel for luma and chroma; 255 means no limit.
Plane plane luma only, chroma U, chroma V, both chromas, all planes all planes Planes that are denoised.
Chroma Chroma on/off on Use chroma in the motion search.
Contrasharp contrasharp −1–100 0 (off) −1 uses ContraSharpening (ContraHD on HD clips). Values above 0 use LSFmod with that strength; around 50 is similar to ContraSharpening.

Search clip

Control Parameter Range / values Hybrid default Meaning
Prefilter prefilter off, light controlled gauss blur, mild median/gauss blur, strong median/gauss blur, dfttest, KNLmeansCL off Filter applied to the search clip only.
Str Str 0–8 1.00 Brightening of dark areas in the search clip. 1 means no change.
Amp Amp 0–1 0.0625 Amplitude of that brightening.

Motion search

Control Parameter Range / values Hybrid default Meaning
Search search one time, nStep, logarithmic, exhaustive, hexagon, uneven multi hexagon, pure horizontal, pure vertical hexagon Search algorithm.
TrueMotion truemotion auto, SD, HD auto Motion field smoothing preset. Auto is on for SD and off for HD (wider than 1099 or taller than 599 pixels).
Blocksize blksize auto, 4, 8, 16 auto Block size of the motion search. Auto is 8 for SD and 16 for HD.
Overlap overlap auto, 2, 4, 8 auto Block overlap; at most half the block size. Auto is half the block size.
Pel pel auto, full-pixel, half-pixel, quarter-pixel auto Pixel accuracy of the search. Auto is full-pixel for HD and half-pixel for SD.
SubPixel subpixel bilinear, bicubic, sharper Wiener, nnedi3 sharper Wiener Interpolation used for the sub-pixel search.
Refine Motion RefineMotion on/off off Recalculates the vectors with half the block size. Needs a block size of at least 8.
thSCD1 thSCD1 1–64000 off Scene change threshold per block. With the check box off the script uses its own value, (2.5 × block size)².
thSCD2 thSCD2 1–64000 130 Scene change threshold: how large a part of the blocks has to change before a scene change is assumed.

Example

Default settings on a 10-bit YUV 4:2:0 source (no conversion is needed):

SMDegrain(interlaced=false)

How Hybrid calls it

  • Hybrid loads the SMDegrain script, mvtools2.dll, masktools2.dll and the neo-smo helpers, plus nnedi3, dfttest, KNLMeansCL, LSFmod and their helpers only when the chosen options need them.
  • The script works on planar YUV 4:2:0, 4:2:2 and 4:4:4 at 8–16 bit integer. Hybrid converts other color spaces before the filter.
  • interlaced is always written, true for interlaced input. The clip height must be divisible by 4 then.
  • All other values are only written when they differ from the defaults. SAD -C is written whenever it is not half of SAD. thSCD1 is only written when its check box is ticked. Quarter-pixel Pel is written as pel=4; with auto nothing is written and the script picks the value from the frame size.
  • Overlap is written as the selected value (2, 4 or 8).
  • SMDegrain also offers the common options and can be added to the filter queue several times.

Background

The script is "Simple MDegrain Mod" 3.1.2d, based on an idea of Caroliano and extended by Dogway, in a build that adds MDegrain4–6 and native high bit depth. Later releases by Dogway (4.x) use a different prefilter numbering and other defaults, and offer more options than shown here.

See also: Vapoursynth SMDegrain, MDegrain, MCDegrainSharp

Sources