Vapoursynth KNLMeansCL

From wiki.selur.net
Revision as of 21:53, 14 November 2026 by Selur (talk | contribs) (New filter page (via create-page on MediaWiki MCP Server))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

KNLMeansCL is a non-local means denoiser. For each pixel it looks for similar patches in its surroundings and in the neighbor frames and averages them by similarity; this removes noise while keeping repeating structures. The original plugin runs on OpenCL; Hybrid can also use CPU, Vulkan and CUDA versions of the algorithm.

Filtering → Vapoursynth → DeNoise

KNLMeansCL controls in Hybrid
KNLMeansCL controls in Hybrid

What it does

Around each pixel a search window is scanned; every candidate patch is compared with the patch around the pixel, and the more similar it is, the more it contributes to the average. With Distance above 0 the same search runs in the neighbor frames.

Settings

Control Parameter Range / values Hybrid default Meaning
Distance d 0 – 100 1 Frames on each side (2d+1 in total); 0 = spatial only.
Search radius a 1 – 16 2 Search window of (2a+1)² pixels.
Similarity radius s 1 – 8 4 Compared patch of (2s+1)² pixels.
Strength h 0.01 – 50 1.2 Higher removes more noise.
Channels channels auto, Y, UV, YUV, RGB auto Planes that are filtered; auto filters RGB clips as RGB and YUV clips on all planes.
Weighting wmode Welsch, Modified Bisquare (less robust), Bisquare, Modified Bisquare (more robust) Welsch Weighting function.
Device type device_type cpu, gpu gpu OpenCL device class; knlm only.
Device device_id 0 – 4 0 Device number; for knlm on the GPU and for vszipcl/vszipcu.
Tools: NLMeans – knlm, vszip, nlm_ispc, knlmvk, vszipcl, vszipcu knlm (macOS: vszip) Implementation: knlm (OpenCL), vszip and nlm_ispc (CPU), knlmvk (Vulkan, VapourSynth R80+), vszipcl (OpenCL), vszipcu (NVIDIA CUDA).

Example

Default settings on a 10-bit YUV 4:2:0 source (YUV goes through the wrapper):

# denoising using KNLMeansCL
clip = denoise.KNLMeansCL(clip, device_type="gpu", device_id=0, tools={'nlmeans': 'knlm'})

How Hybrid calls it

  • RGB clips are filtered directly. For YUV clips with auto or YUV Hybrid uses a small wrapper from its script collection: 4:4:4 in one pass, subsampled clips first on luma and then on chroma, gray clips on luma.
  • Values are only written when they differ from the defaults; the device type is always written for knlm, the device number for knlm on the GPU and for vszipcl/vszipcu.
  • With knlmvk the frames are downloaded from the GPU afterwards.
  • KNLMeansCL also offers the common options (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick).

Background

KNLMeansCL

Khanattila's KNLMeansCL is an OpenCL implementation of non-local means for AviSynth and VapourSynth (GPL-3.0). Its own channels=auto filters only luma on YUV clips, and its own device_type=auto tries accelerators, then GPUs, then the CPU. An optional reference clip can be used to compute the weights; frames up to 8192×8192 are supported.

The other implementations

The CPU and GPU ports give similar but not identical pictures: knlm, nlm_ispc and the vszip versions form three groups.

Sources