Skip to content

funcs

Classes:

Functions:

DebandPassPresets

Attributes:

LIGHT class-attribute instance-attribute

LIGHT = (
    (F3kdb(16, 120), False, False),
    (F3kdb(31, 160), False, True),
    (Placebo(8, 2.5), False, False),
    (Placebo(16, 1.5), False, True),
    (Placebo(24, 1.0), False, True),
)

MEDIUM class-attribute instance-attribute

MEDIUM = (
    (F3kdb(16, 120), False, False),
    (F3kdb(31, 160), False, True),
    (Placebo(8, 1.75), False, False),
    (Placebo(16, 1.275), False, True),
    (Placebo(24, 0.8), False, True),
)

STRONG class-attribute instance-attribute

STRONG = (
    (F3kdb(16, 120), False, False),
    (F3kdb(31, 160), True, False),
    (Placebo(8, 2.5), False, False),
    (Placebo(16, 1.5), True, False),
    (Placebo(24, 1.0), True, False),
)

guided_deband

guided_deband(
    clip: VideoNode,
    radius: int | list[int] | None = None,
    strength: float = 0.3,
    thr: int | tuple[int, int] | None = None,
    mode: GuidedFilterMode = GRADIENT,
    rad: int = 0,
    bin_thr: float | list[float] | None = 0,
    planes: PlanesT = None,
    range_in: ColorRange | None = None,
    **kwargs: Any
) -> VideoNode
Source code
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
def guided_deband(
    clip: vs.VideoNode, radius: int | list[int] | None = None, strength: float = 0.3,
    thr: int | tuple[int, int] | None = None, mode: GuidedFilterMode = GuidedFilterMode.GRADIENT,
    rad: int = 0, bin_thr: float | list[float] | None = 0, planes: PlanesT = None,
    range_in: ColorRange | None = None, **kwargs: Any
) -> vs.VideoNode:
    assert check_variable(clip, guided_deband)

    planes = normalize_planes(clip, planes)

    range_in = ColorRange.from_param_or_video(range_in, clip)

    rad = fallback(rad, ceil(clip.height / 540))

    if bin_thr is None:
        if clip.format.sample_type is vs.FLOAT:
            bin_thr = 1.5 / 255 if range_in.is_full else [1.5 / 219, 1.5 / 224]
        else:
            bin_thr = scale_value(0.005859375, 32, clip, range_out=range_in)

    bin_thr = normalize_seq(bin_thr, clip.format.num_planes)

    deband = guided_filter(clip, None, radius, strength, mode, planes=planes, **kwargs)

    if thr:
        deband = limit_filter(deband, clip, thr=thr)

    if rad:
        morpho = Morpho(planes)
        rmask = ExprOp.SUB.combine(morpho.expand(clip, rad), morpho.inpand(clip, rad), planes=planes)

        if bin_thr and max(bin_thr) > 0:
            rmask = rmask.std.Binarize(threshold=bin_thr, planes=planes)

        rmask = remove_grain(rmask, RemoveGrainMode.OPP_CLIP_AVG_FAST)
        rmask = BlurMatrix.BINOMIAL()(rmask)
        rmask = remove_grain(rmask, RemoveGrainMode.MIN_SHARP)

        deband = deband.std.MaskedMerge(clip, rmask, planes=planes)

    return deband

masked_deband

masked_deband(
    clip: VideoNode,
    radius: int = 16,
    thr: float | list[float] = 96,
    grain: float | list[float] = [0.23, 0],
    sigma: float = 1.25,
    rxsigma: list[int] = [50, 220, 300],
    pf_sigma: float | None = 1.25,
    brz: tuple[float, float] = (0.038, 0.068),
    rg_mode: RemoveGrainModeT = MINMAX_MEDIAN_OPP,
    debander: type[Debander] | Debander = F3kdb,
    **kwargs: Any
) -> VideoNode
Source code
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
def masked_deband(
    clip: vs.VideoNode, radius: int = 16,
    thr: float | list[float] = 96, grain: float | list[float] = [0.23, 0],
    sigma: float = 1.25, rxsigma: list[int] = [50, 220, 300],
    pf_sigma: float | None = 1.25, brz: tuple[float, float] = (0.038, 0.068),
    rg_mode: RemoveGrainModeT = RemoveGrainMode.MINMAX_MEDIAN_OPP,
    debander: type[Debander] | Debander = F3kdb, **kwargs: Any
) -> vs.VideoNode:
    clip, bits = expect_bits(clip, 16)

    if not isinstance(debander, Debander):
        debander = debander()

    deband_mask = deband_detail_mask(clip, sigma, rxsigma, pf_sigma, brz, rg_mode)

    deband = debander.deband(clip, radius=radius, thr=thr, grain=grain, **kwargs)

    masked = deband.std.MaskedMerge(clip, deband_mask)

    return depth(masked, bits)

mdb_bilateral

mdb_bilateral(
    clip: VideoNode,
    radius: int = 16,
    thr: int | list[int] = 260,
    lthr: int | tuple[int, int] = (153, 0),
    elast: float = 3.0,
    bright_thr: int | None = None,
    debander: type[Debander] | Debander = F3kdb,
) -> VideoNode

Multi stage debanding, bilateral-esque filter.

This function is more of a last resort for extreme banding. Recommend values are ~40-60 for luma and chroma strengths.

Parameters:

  • clip

    (VideoNode) –

    Input clip.

  • radius

    (int, default: 16 ) –

    Banding detection range.

  • thr

    (int | list[int], default: 260 ) –

    Banding detection thr(s) for planes.

  • lthr

    (int | tuple[int, int], default: (153, 0) ) –

    Threshold of the limiting. Refer to vsrgtools.limit_filter.

  • elast

    (float, default: 3.0 ) –

    Elasticity of the limiting. Refer to vsrgtools.limit_filter.

  • bright_thr

    (int | None, default: None ) –

    Limiting over the bright areas. Refer to vsrgtools.limit_filter.

  • debander

    (type[Debander] | Debander, default: F3kdb ) –

    Specify what Debander to use. You can pass an instance with custom arguments.

Returns:

  • VideoNode

    Debanded clip.

Source code
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def mdb_bilateral(
    clip: vs.VideoNode, radius: int = 16,
    thr: int | list[int] = 260,
    lthr: int | tuple[int, int] = (153, 0), elast: float = 3.0,
    bright_thr: int | None = None,
    debander: type[Debander] | Debander = F3kdb
) -> vs.VideoNode:
    """
    Multi stage debanding, bilateral-esque filter.

    This function is more of a last resort for extreme banding.
    Recommend values are ~40-60 for luma and chroma strengths.

    :param clip:        Input clip.
    :param radius:      Banding detection range.
    :param thr:         Banding detection thr(s) for planes.
    :param lthr:        Threshold of the limiting. Refer to `vsrgtools.limit_filter`.
    :param elast:       Elasticity of the limiting. Refer to `vsrgtools.limit_filter`.
    :param bright_thr:  Limiting over the bright areas. Refer to `vsrgtools.limit_filter`.
    :param debander:    Specify what Debander to use. You can pass an instance with custom arguments.

    :return:            Debanded clip.
    """

    assert check_variable(clip, mdb_bilateral)

    if not isinstance(debander, Debander):
        debander = debander()

    clip, bits = expect_bits(clip, 16)

    rad1, rad2, rad3 = round(radius * 4 / 3), round(radius * 2 / 3), round(radius / 3)

    db1 = debander.deband(clip, radius=rad1, thr=[max(1, th // 2) for th in to_arr(thr)], grain=0.0)
    db2 = debander.deband(db1, radius=rad2, thr=thr, grain=0)
    db3 = debander.deband(db2, radius=rad3, thr=thr, grain=0)

    limit = limit_filter(db3, db2, clip, thr=lthr, elast=elast, bright_thr=bright_thr)

    return depth(limit, bits)

multi_deband

multi_deband(
    clip: VideoNode,
    *passes: Debander | tuple[Debander, bool] | tuple[Debander, bool, bool],
    ref: VideoNode | None = None,
    base_db: Debander = F3kdb(8, 100),
    lowpass_db: Debander = Placebo(24, 6.0),
    edgemask: VideoNode | None = None,
    textures: VideoNode | None = None,
    **freq_merge_kwargs: Any
) -> VideoNode
Source code
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
def multi_deband(
    clip: vs.VideoNode, *passes: Debander | tuple[Debander, bool] | tuple[Debander, bool, bool],
    ref: vs.VideoNode | None = None, base_db: Debander = F3kdb(8, 100), lowpass_db: Debander = Placebo(24, 6.0),
    edgemask: vs.VideoNode | None = None, textures: vs.VideoNode | None = None, **freq_merge_kwargs: Any
) -> vs.VideoNode:
    ref = check_ref_clip(clip, ref, multi_deband)

    if edgemask is None:
        edgemask = FDoG.edgemask(ref, 0.25, 1.0, 2, planes=(0, True))

    if textures is None:
        edges = flat_mask(ref, 6, 0.025, False)

        textures = ExprOp.MAX(
            texture_mask(ref, thr=0.001, blur=3, points=[
                (False, 1.15), (True, 1.75), (False, 2.5),
                (True, 5.0), (False, 7.5), (False, 10.0)
            ]).resize.Bicubic(format=vs.YUV444P16), split_planes=True
        )
        textures = box_blur(ExprOp.SUB(textures, edges), 2)
        textures = norm_expr(textures, 'x 2 *', func=guided_filter)

    line_big = ExprOp.ADD(
        edgemask, gauss_blur(edgemask.std.Maximum(), 0.75), expr_suffix='4 *'
    ).std.Maximum()

    linemask_deband = gauss_blur(line_big.std.BinarizeMask(20 << 10), 0.45)

    base_deband = base_db.deband(clip)
    lowpass_deband = lowpass_db.deband(clip).std.MaskedMerge(base_deband, linemask_deband)

    freq_merge_kwargs = dict(mode_high=MeanMode.HARMONIC) | freq_merge_kwargs

    def _norm_pass(
        dbpass: Debander | tuple[Debander, bool] | tuple[Debander, bool, bool]
    ) -> tuple[Debander, bool, bool]:
        mask, base_db = False, True

        if isinstance(dbpass, tuple):
            debander, mask, *other = dbpass

            if other:
                base_db = other[0]
        else:
            debander = dbpass

        return debander, mask, base_db

    deband = frequency_merge(
        base_deband,
        (
            debanded
            if (debanded := debander.deband(clip if base_db else base_deband))
            and not mask else debanded.std.MaskedMerge(base_deband, textures)
            for debander, mask, base_db in map(_norm_pass, passes)
        ),
        lowpass=lambda *args, **kwargs: lowpass_deband, **freq_merge_kwargs
    )

    return deband.std.MaskedMerge(clip.std.Merge(base_deband, 0.5), textures)

pfdeband

pfdeband(
    clip: VideoNode,
    radius: int = 16,
    thr: float | list[float] = 96,
    lthr: float | tuple[float, float] = 0.5,
    elast: float = 1.5,
    bright_thr: int | None = None,
    prefilter: Prefilter | VSFunctionKwArgs[VideoNode, VideoNode] = gauss_blur,
    debander: type[Debander] | Debander = F3kdb,
    planes: PlanesT = None,
    **kwargs: Any
) -> VideoNode

Prefilter and deband a clip.

Parameters:

  • clip

    (VideoNode) –

    Input clip.

  • radius

    (int, default: 16 ) –

    Banding detection range.

  • thr

    (float | list[float], default: 96 ) –

    Banding detection thr(s) for planes.

  • lthr

    (float | tuple[float, float], default: 0.5 ) –

    Threshold of the limiting. Refer to vsrgtools.limit_filter.

  • elast

    (float, default: 1.5 ) –

    Elasticity of the limiting. Refer to vsrgtools.limit_filter.

  • bright_thr

    (int | None, default: None ) –

    Limiting over the bright areas. Refer to vsrgtools.limit_filter.

  • prefilter

    (Prefilter | VSFunctionKwArgs[VideoNode, VideoNode], default: gauss_blur ) –

    Prefilter used to blur the clip before debanding.

  • debander

    (type[Debander] | Debander, default: F3kdb ) –

    Specify what Debander to use. You can pass an instance with custom arguments.

  • planes

    (PlanesT, default: None ) –

    Planes to process

Returns:

  • VideoNode

    Debanded clip.

Source code
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
def pfdeband(
    clip: vs.VideoNode, radius: int = 16, thr: float | list[float] = 96,
    lthr: float | tuple[float, float] = 0.5, elast: float = 1.5,
    bright_thr: int | None = None, prefilter: Prefilter | VSFunctionKwArgs[vs.VideoNode, vs.VideoNode] = gauss_blur,
    debander: type[Debander] | Debander = F3kdb, planes: PlanesT = None,
    **kwargs: Any
) -> vs.VideoNode:
    """
    Prefilter and deband a clip.

    :param clip:          Input clip.
    :param radius:        Banding detection range.
    :param thr:           Banding detection thr(s) for planes.
    :param lthr:          Threshold of the limiting. Refer to `vsrgtools.limit_filter`.
    :param elast:         Elasticity of the limiting. Refer to `vsrgtools.limit_filter`.
    :param bright_thr:    Limiting over the bright areas. Refer to `vsrgtools.limit_filter`.
    :param prefilter:     Prefilter used to blur the clip before debanding.
    :param debander:      Specify what Debander to use. You can pass an instance with custom arguments.
    :param planes:        Planes to process

    :return:              Debanded clip.
    """
    func = FunctionUtil(clip, pfdeband, planes, (vs.YUV, vs.GRAY), (8, 16))

    if not isinstance(debander, Debander):
        debander = debander()

    blur = prefilter(func.work_clip, planes=planes, **kwargs)
    diff = func.work_clip.std.MakeDiff(blur, planes=planes)

    deband = debander.deband(blur, radius=radius, thr=thr, planes=planes)

    merge = deband.std.MergeDiff(diff, planes=planes)
    limit = limit_filter(merge, func.work_clip, thr=lthr, elast=elast, bright_thr=bright_thr)

    return func.return_clip(limit)