Vapoursynth Bilateral (GLSL)

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

Bilateral (GLSL) is a spatial, edge-preserving denoiser. It runs the bilateral denoise shaders of Anime4K on the GPU: flat areas are smoothed while edges stay sharp.

Filtering → Vapoursynth → DeNoise

Bilateral (GLSL) controls in Hybrid
Bilateral (GLSL) controls in Hybrid

What it does

Each pixel is replaced by a combination of its neighbors. A neighbor counts more the closer it is in position (Spatial) and in brightness (Intensity), so pixels across an edge hardly contribute. Three variants exist:

  • Mean – weighted average, per channel (a classic bilateral filter).
  • Median – weighted median; neighbors are weighed by luma similarity and distance.
  • Mode – the neighbor with the highest weight (weighted mode), with histogram regularization.

The filter works on single frames only.

Requirements

  • vs-placebo with a working Vulkan GPU.
  • The GLSL shader folder that comes with Hybrid; without it the filter is not offered.

Settings

Control Parameter Range / values Hybrid default Meaning
Mode shader file Mean, Median, Mode Mean Which of the three shaders runs.
Intensity INTENSITY_SIGMA 0.01 – 100 0.1 Width of the brightness window; higher denoises more.
Spatial SPATIAL_SIGMA 0.01 – 100 1 Width of the distance window; it also sets the kernel size (Mean: 5×5 at 1, Median/Mode: 3×3 below 2). Large values are slow.
Intensity PowerCurve INTENSITY_POWER_CURVE 0 – 100 1 0 treats all brightness levels the same; higher values narrow the window in dark areas and widen it in bright ones.
Histogram regularization (Median) HISTOGRAM_REGULARIZATION 0 – 100 0 Window width of the regularization; 0 = plain weighted median, higher values move the result towards a bilateral "closest to mean" result.
Histogram regularization (Mode) HISTOGRAM_REGULARIZATION 0.01 – 100 0.2 Same for the Mode shader; must be above 0.

The histogram regularization is disabled for Mean and shows the value of the chosen mode.

Example

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

# adjusting color space from YUV420P10 to YUV444P16 for vsGLSLBilateral
clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16)
# denoising using Anime4K_Denoise_Bilateral
with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/Anime4K_Denoise_Bilateral_Mean.glsl") as glslf:
  glsl = glslf.read()
glsl = glsl.replace('#define INTENSITY_SIGMA 0.1', '#define INTENSITY_SIGMA 0.1')
glsl = glsl.replace('#define SPATIAL_SIGMA 1.0', '#define SPATIAL_SIGMA 1')
glsl = glsl.replace('#define INTENSITY_POWER_CURVE 1.0', '#define INTENSITY_POWER_CURVE 1')
clip = core.placebo.Shader(clip, shader_s=glsl, width=clip.width, height=clip.height, matrix=1)

How Hybrid calls it

  • The clip is converted to YUV 4:4:4 16 bit, the only format the shader filter takes; the output stays in that format.
  • Hybrid reads the chosen shader, replaces its default values with the values from the GUI and passes the text to vs-placebo's Shader function with the clip's color matrix. The size does not change.
  • Intensity, Spatial and PowerCurve are always written; the histogram regularization only for Median and Mode.
  • Bilateral (GLSL) also offers the common options (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick).

Background

Anime4K shaders

The shaders come from bloc97's Anime4K (MIT license), version 3.2, and are written as mpv user shaders. vs-placebo runs such shaders in VapourSynth: it takes 16-bit YUV and returns YUV 4:4:4 16 bit.

Sources