Skip to content

limit

Functions:

  • limit_filter

    Performs a soft-limiting between two clips to limit the difference of filtering while avoiding artifacts.

limit_filter

limit_filter(
    flt: VideoNode,
    src: VideoNode,
    ref: VideoNode | None = None,
    dark_thr: float | Sequence[float] = 1.0,
    bright_thr: float | Sequence[float] = 1.0,
    elast: float | Sequence[float] = 2.0,
    planes: PlanesT = None,
) -> VideoNode

Performs a soft-limiting between two clips to limit the difference of filtering while avoiding artifacts.

Parameters:

  • flt

    (VideoNode) –

    Filtered clip.

  • src

    (VideoNode) –

    Source clip.

  • ref

    (VideoNode | None, default: None ) –

    Reference clip, to compute the weight to be applied on filtering diff.

  • dark_thr

    (float | Sequence[float], default: 1.0 ) –

    Threshold (8-bit scale) to limit dark filtering diff.

  • bright_thr

    (float | Sequence[float], default: 1.0 ) –

    Threshold (8-bit scale) to limit bright filtering diff.

  • elast

    (float | Sequence[float], default: 2.0 ) –

    Elasticity of the soft threshold.

  • planes

    (PlanesT, default: None ) –

    Planes to process. Defaults to all.

Returns:

  • VideoNode

    Limited clip.

Source code
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def limit_filter(
    flt: vs.VideoNode,
    src: vs.VideoNode,
    ref: vs.VideoNode | None = None,
    dark_thr: float | Sequence[float] = 1.0,
    bright_thr: float | Sequence[float] = 1.0,
    elast: float | Sequence[float] = 2.0,
    planes: PlanesT = None,
) -> vs.VideoNode:
    """
    Performs a soft-limiting between two clips to limit the difference of filtering while avoiding artifacts.

    Args:
        flt: Filtered clip.
        src: Source clip.
        ref: Reference clip, to compute the weight to be applied on filtering diff.
        dark_thr: Threshold (8-bit scale) to limit dark filtering diff.
        bright_thr: Threshold (8-bit scale) to limit bright filtering diff.
        elast: Elasticity of the soft threshold.
        planes: Planes to process. Defaults to all.

    Returns:
        Limited clip.
    """
    ref = fallback(ref, src)

    base_expr = "x y - DIFF! x z - abs DIFF_REF_ABS!"
    dark_expr = (
        "{dark_thr} {elast} * THR! 1 THR@ {dark_thr} - / SLOPE! "
        "DIFF_REF_ABS@ {dark_thr} <= x DIFF_REF_ABS@ THR@ >= y "
        "y DIFF@ THR@ DIFF_REF_ABS@ - * SLOPE@ * + ? ?"
    )
    bright_expr = dark_expr.replace("dark_thr", "bright_thr")

    return norm_expr(
        [flt, src, ref],
        f"{base_expr} x z < {dark_expr} {bright_expr} ?",
        dark_thr=[scale_delta(x, 8, flt) for x in to_arr(dark_thr)],
        bright_thr=[scale_delta(x, 8, flt) for x in to_arr(bright_thr)],
        elast=elast,
        planes=planes,
    )