Skip to content

placebo

Classes:

Placebo dataclass

Placebo(
    radius: float | None = None,
    thr: float | list[float] | None = None,
    grain: float | list[float] | None = None,
    iterations: int | None = None,
    dither: PlaceboDither | None = None,
)

Bases: Debander

Debander wrapper around libplacebo plugin's Deband function.

Methods:

  • deband

    Main deband function, wrapper for placebo.Deband <https:/github.com/Lypheo/vs-placebo#vs-placebo>_

Attributes:

dither class-attribute instance-attribute

dither: PlaceboDither | None = None

grain class-attribute instance-attribute

grain: float | list[float] | None = None

iterations class-attribute instance-attribute

iterations: int | None = None

radius class-attribute instance-attribute

radius: float | None = None

thr class-attribute instance-attribute

thr: float | list[float] | None = None

deband

deband(
    clip: VideoNode,
    radius: float = 16.0,
    thr: float | list[float] = 3.0,
    iterations: int = 4,
    grain: float | list[float] = 0.0,
    dither: PlaceboDither = DEFAULT,
) -> VideoNode

Main deband function, wrapper for placebo.Deband <https:/github.com/Lypheo/vs-placebo#vs-placebo>_

Parameters:

  • clip

    (VideoNode) –

    Source clip

  • radius

    (float, default: 16.0 ) –

    The debanding filter's initial radius. The radius increases linearly for each iteration. A higher radius will find more gradients, but a lower radius will smooth more aggressively.

  • thr

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

    The debanding filter's cut-off threshold. Higher numbers increase the debanding strength dramatically, but progressively diminish image details.

  • iterations

    (int, default: 4 ) –

    The number of debanding steps to perform per sample. Each step reduces a bit more banding, but takes time to compute. Note that the strength of each step falls off very quickly, so high numbers (> 4) are practically useless.

  • grain

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

    Add some extra noise to the image. This significantly helps cover up remaining quantization artifacts. Higher numbers add more noise. Note: When debanding HDR sources, even a small amount of grain can result in a very big change to the brightness level. It's recommended to either scale this value down or disable it entirely for HDR.

  • dither

    (PlaceboDither, default: DEFAULT ) –

    Specify what kind of Placebo dithering will be used.

Returns:

  • VideoNode

    Debanded clip

Source code
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
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
137
138
139
140
141
142
143
@inject_self
def deband(  # type: ignore[override]
    self, clip: vs.VideoNode, radius: float = 16.0, thr: float | list[float] = 3.0,
    iterations: int = 4, grain: float | list[float] = 0.0, dither: PlaceboDither = PlaceboDither.DEFAULT
) -> vs.VideoNode:
    """
    Main deband function, wrapper for `placebo.Deband <https:/github.com/Lypheo/vs-placebo#vs-placebo>`_

    :param clip:            Source clip
    :param radius:          The debanding filter's initial radius.
                            The radius increases linearly for each iteration.
                            A higher radius will find more gradients,
                            but a lower radius will smooth more aggressively.
    :param thr:             The debanding filter's cut-off threshold.
                            Higher numbers increase the debanding strength dramatically,
                            but progressively diminish image details.
    :param iterations:      The number of debanding steps to perform per sample.
                            Each step reduces a bit more banding,
                            but takes time to compute.
                            Note that the strength of each step falls off very quickly,
                            so high numbers (> 4) are practically useless.
    :param grain:           Add some extra noise to the image.
                            This significantly helps cover up remaining quantization artifacts.
                            Higher numbers add more noise.
                            Note: When debanding HDR sources, even a small amount of grain can result
                            in a very big change to the brightness level.
                            It's recommended to either scale this value down or disable it entirely for HDR.
    :param dither:          Specify what kind of Placebo dithering will be used.

    :return:                Debanded clip
    """

    assert check_variable(clip, self.__class__.deband)

    radius = fallback(self.radius, radius)
    thr = normalize_seq(fallback(self.thr, thr))  # type: ignore[arg-type]
    iterations = fallback(self.iterations, iterations)
    grain = normalize_seq(fallback(self.grain, grain))  # type: ignore[arg-type]
    dither = fallback(self.dither, dither)

    def _placebo(clip: vs.VideoNode, thr: float, grain: float, planes: Iterable[int]) -> vs.VideoNode:
        plane = 0
        for p in planes:
            plane |= pow(2, p)
        return clip.placebo.Deband(plane, iterations, thr, radius, grain * (1 << 5) * 0.8, **dither.placebo_args)

    set_grn = set(grain)

    if set_grn == {0} or clip.format.num_planes == 1:
        debs = [_placebo(p, thr, grain[0], [0]) for p, thr in zip(split(clip), thr)]

        if len(debs) == 1:
            return debs[0]

        return join(debs, clip.format.color_family)

    plane_map = {
        tuple(i for i in range(clip.format.num_planes) if grain[i] == x): x for x in set_grn - {0}
    }

    debanded = clip
    for planes, grain_val in plane_map.items():
        if len(set(thr[p] for p in planes)) == 1:
            debanded = _placebo(debanded, thr[planes[0]], grain_val, planes)
        else:
            for p in planes:
                debanded = _placebo(debanded, thr[p], grain_val, planes)

    return debanded

PlaceboDither

Bases: CustomIntEnum

Attributes:

  • BLUE_NOISE

    Dither with blue noise. Very high quality, but requires the use of a

  • DEFAULT
  • NONE

    No dithering.

  • ORDERED_FIXED

    The same as ORDERED_LUT, but uses fixed function math instead

  • ORDERED_LUT

    Dither with an ordered (bayer) dither matrix, using a LUT. Low quality,

  • WHITE_NOISE

    Dither with white noise. This does not require a LUT and is fairly cheap

  • placebo_args (KwargsT) –

    Get arguments you must pass to .placebo.Debander for this dither mode.

BLUE_NOISE class-attribute instance-attribute

BLUE_NOISE = 0

Dither with blue noise. Very high quality, but requires the use of a LUT. Warning: Computing a blue noise texture with a large size can be very slow, however this only needs to be performed once. Even so, using this with a lut_size greater than 6 is generally ill-advised. This is the preferred/default dither method.

DEFAULT class-attribute instance-attribute

DEFAULT = BLUE_NOISE

NONE class-attribute instance-attribute

NONE = -1

No dithering.

ORDERED_FIXED class-attribute instance-attribute

ORDERED_FIXED = 2

The same as ORDERED_LUT, but uses fixed function math instead of a LUT. This is faster, but only supports a fixed dither matrix size of 16x16 (equal to a lut_size of 4). Requires GLSL 130+.

ORDERED_LUT class-attribute instance-attribute

ORDERED_LUT = 1

Dither with an ordered (bayer) dither matrix, using a LUT. Low quality, and since this also uses a LUT, there's generally no advantage to picking this instead of BLUE_NOISE. It's mainly there for testing.

WHITE_NOISE class-attribute instance-attribute

WHITE_NOISE = 3

Dither with white noise. This does not require a LUT and is fairly cheap to compute. Unlike the other modes it doesn't show any repeating patterns either spatially or temporally, but the downside is that this is visually fairly jarring due to the presence of low frequencies in the noise spectrum. Used as a fallback when the above methods are not available.

placebo_args property

placebo_args: KwargsT

Get arguments you must pass to .placebo.Debander for this dither mode.