Avisynth NNEDI3 Resize

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

NNEDI3Resize enlarges the picture with the nnedi3 neural-network interpolator. It doubles the size step by step until the target is covered and then fits the result to the exact target size with a normal resizer.

Filtering → Avisynth → Frame → Resize (tick Resizer: and choose NNEDI3Resize)

NNEDI3Resize controls in Hybrid
NNEDI3Resize controls in Hybrid

What it does

nnedi3 predicts the missing pixels of a doubled picture with a small neural network. Edges stay clean and free of the jaggies that normal kernels leave when enlarging. It can only enlarge, by 2×, 4×, 8× and so on. Hybrid picks the smallest power of two that reaches the target in both dimensions and lets a classic resizer (the Resizer list) shift the picture to the right center and scale it to the exact size. Optionally the doubling runs on the GPU through OpenCL.

Requirements

  • OpenCL mode needs a GPU with OpenCL support; without one the option is disabled.
  • nnedi3_weights.bin has to stay next to the plugins.

Settings

Control Parameter Range Hybrid default Meaning
Neighbours nsize 0–6 0 Size of the neighbourhood the network looks at (0 = 8×6 … 6 = 32×4). 0 or 4 is recommended for enlarging.
Neurons nns 0–4 3 Number of neurons: 0 = 16, 1 = 32, 2 = 64, 3 = 128, 4 = 256. More is slower and slightly better.
Quality qual 1–2 1 2 is slower and a little better.
EType etype 0–1 0 Error measure of the network weights: 0 minimizes the absolute error, 1 the squared error.
Prescreener pscrn 0–4 2 Fast pre-selection of pixels that need no network: 0 none, 1 original, 2–4 newer levels. With OpenCL the maximum is 2.
Resizer cshift list Spline36Resize Core resizer used for the center-shift correction and the final fit: BilinearResize, BicubicResize, BlackmanResize, GaussResize, LanczosResize, PointResize, SincResize, Spline16Resize, Spline36Resize, Spline64Resize.
OpenCL – on/off off Does the doubling on the GPU (NNEDI3CL).
Device device 0–15 0 OpenCL device number; only used with OpenCL on.

Example

Default settings on a 10-bit YUV 4:2:0 source (640x352), enlarged to 1280x704:

# current resolution: 640x352
# scaling to 1280x704
nnedi3_rpow2(rfactor=2,cshift="Spline36Resize",fwidth=1280,fheight=704)

How Hybrid calls it

  • Hybrid uses LanczosResize instead (and writes a script comment) when the target is smaller than the current size in either dimension, or when the current width is not a multiple of 4.
  • CPU: nnedi3_rpow2(rfactor=…, cshift="…", fwidth=W, fheight=H). nsize, nns, qual, etype and pscrn are only written when they differ from the defaults.
  • OpenCL: one NNEDI3CL call per doubling step with nsize, nns and qual always written (etype, pscrn and device only when not default), followed by the chosen resizer with a source offset of −0.5 × (factor − 1) pixels in both directions to realign the picture. OpenCL mode accepts 8-bit planar YUV and gray only, so Hybrid converts other formats first.
  • NNEDI3Resize also offers the common options and can be added to the filter queue several times.

Background

  • The CPU version is the nnedi3 plugin by jpsdr (a fork of tritical's nnedi3) whose nnedi3_rpow2 is built in. The OpenCL version is NNEDI3CL by Asd-g; its results are close to, but not identical with, the CPU version.
  • nnedi3_rpow2 also has ep0/ep1 (b/c or taps of the final resizer), threads and opt; Hybrid does not offer them.
  • Used alone, nnedi3 defaults to nsize 6 and nns 1; nnedi3_rpow2 defaults to 0 and 3, which are Hybrid's defaults.

See also: Vapoursynth NNEDI3 Resize, Avisynth Resizer

Sources