Skip to content

f3kdb

Classes:

  • F3kdb

    Debander wrapper around the f3kdb plugin.

  • RandomAlgo

    Random number algorithm for reference positions / grains.

  • SampleMode

RandomAlgoT module-attribute

F3kdb dataclass

F3kdb(
    radius: int | None = None,
    thr: int | list[int] | None = None,
    grain: int | list[int] | None = None,
    sample_mode: SampleMode | SampleModeMidDiffInfo | None = None,
    seed: int | None = None,
    dynamic_grain: int | None = None,
    blur_first: bool | None = None,
)

Bases: Debander

Debander wrapper around the f3kdb plugin.

Methods:

  • deband

    :param clip: Input clip.

Attributes:

blur_first class-attribute instance-attribute

blur_first: bool | None = None

dynamic_grain class-attribute instance-attribute

dynamic_grain: int | None = None

grain class-attribute instance-attribute

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

radius class-attribute instance-attribute

radius: int | None = None

sample_mode class-attribute instance-attribute

sample_mode: SampleMode | SampleModeMidDiffInfo | None = None

seed class-attribute instance-attribute

seed: int | None = None

thr class-attribute instance-attribute

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

deband

deband(
    clip: VideoNode,
    radius: int = 16,
    thr: int | list[int] = 96,
    grain: float | list[float] = 0.0,
    sample_mode: SampleMode | SampleModeMidDiffInfo = SQUARE,
    dynamic_grain: bool = False,
    blur_first: bool | None = None,
    seed: int | None = None,
    random: RandomAlgoT | tuple[RandomAlgoT, RandomAlgoT] = UNIFORM,
    planes: PlanesT = None,
    _func: FuncExceptT | None = None,
) -> VideoNode

Parameters:

  • clip

    (VideoNode) –

    Input clip.

  • radius

    (int, default: 16 ) –

    Banding detection range.

  • thr

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

    Banding detection threshold for respective plane. If difference between current pixel and reference pixel is less than threshold, it will be considered as banded

  • grain

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

    Specifies amount of grains added in the last debanding stage.

  • sample_mode

    (SampleMode | SampleModeMidDiffInfo, default: SQUARE ) –

    Determines how pixels are taken as reference.

  • dynamic_grain

    (bool, default: False ) –

    Use different grain pattern for each frame.

  • blur_first

    (bool | None, default: None ) –

    If True current pixel is compared with average value of all pixels. If False current pixel is compared with all pixels. The pixel is considered as banded pixel only if all differences are less than threshold.

  • seed

    (int | None, default: None ) –

    Seed for random number generation

  • random

    (RandomAlgoT | tuple[RandomAlgoT, RandomAlgoT], default: UNIFORM ) –

    Random number algorithm for reference positions / grains.

  • planes

    (PlanesT, default: None ) –

    Which planes to process.

Source code
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
@inject_self
def deband(  # type: ignore[override]
    self, clip: vs.VideoNode,
    radius: int = 16,
    thr: int | list[int] = 96,
    grain: float | list[float] = 0.0,
    sample_mode: SampleMode | SampleModeMidDiffInfo = SampleMode.SQUARE,
    dynamic_grain: bool = False,
    blur_first: bool | None = None,
    seed: int | None = None,
    random: RandomAlgoT | tuple[RandomAlgoT, RandomAlgoT] = RandomAlgo.UNIFORM,
    planes: PlanesT = None,
    _func: FuncExceptT | None = None
) -> vs.VideoNode:
    """
    :param clip:            Input clip.
    :param radius:          Banding detection range.
    :param thr:             Banding detection threshold for respective plane.
                            If difference between current pixel and reference pixel is less than threshold,
                            it will be considered as banded
    :param grain:           Specifies amount of grains added in the last debanding stage.
    :param sample_mode:     Determines how pixels are taken as reference.
    :param dynamic_grain:   Use different grain pattern for each frame.
    :param blur_first:      If True current pixel is compared with average value of all pixels.
                            If False current pixel is compared with all pixels.
                            The pixel is considered as banded pixel only if all differences are less than threshold.
    :param seed:            Seed for random number generation
    :param random:          Random number algorithm for reference positions / grains.
    :param planes:          Which planes to process.
    """
    func = FunctionUtil(clip, _func or self.deband, planes, (vs.GRAY, vs.YUV), (8, 16))

    if not hasattr(core, 'neo_f3kdb'):
        raise CustomRuntimeError('You are missing the neo_f3kdb plugin!', func.func)

    if 'y_2' not in core.neo_f3kdb.Deband.__signature__.parameters:  # type: ignore
        raise CustomRuntimeError('You are using an outdated version of neo_f3kdb, upgrade now!', func.func)

    radius = fallback(self.radius, radius)

    y, cb, cr = normalize_seq(fallback(self.thr, thr), 3)
    gry, grc = normalize_seq(fallback(self.grain, grain), 2)

    sample_mode = fallback(self.sample_mode, sample_mode)  # type: ignore

    random_ref, random_grain = normalize_seq(random, 2)

    if isinstance(random_ref, RandomAlgoWithInfo):
        random_algo_ref = int(random_ref)
        random_param_ref = random_ref.sigma
    else:
        random_algo_ref = int(random_ref)
        random_param_ref = 1.0

    if isinstance(random_grain, RandomAlgoWithInfo):
        random_algo_grain = int(random_grain)
        random_param_grain = random_grain.sigma
    else:
        random_algo_grain = int(random_grain)
        random_param_grain = 1.0

    y1 = cb1 = cr1 = y2 = cb2 = cr2 = None

    if isinstance(sample_mode, SampleModeMidDiffInfo):
        y1, cb1, cr1 = func.norm_seq(sample_mode.thr_max, 0)
        y2, cb2, cr2 = func.norm_seq(sample_mode.thr_mid, 0)
        sample_mode = sample_mode.sample_mode

    blur_first = fallback(self.blur_first or blur_first, max(y, cb, cr) < 2048)  # type: ignore

    debanded = core.neo_f3kdb.Deband(
        func.work_clip, radius, y, cb, cr, gry * 255 * 0.8, grc * 255 * 0.8,  # type: ignore
        sample_mode.value, self.seed or seed, blur_first, self.dynamic_grain or dynamic_grain,
        None, None, None, False, 16, random_algo_ref, random_algo_grain,
        random_param_ref, random_param_grain, None, y1, cb1, cr1, y2, cb2, cr2, True
    )

    return func.return_clip(debanded)

RandomAlgo

Bases: CustomIntEnum

Random number algorithm for reference positions / grains.

Methods:

Attributes:

  • GAUSSIAN

    Gaussian distribution

  • OLD

    Algorithm in old versions

  • UNIFORM

    Uniform distribution

GAUSSIAN class-attribute instance-attribute

GAUSSIAN = 2

Gaussian distribution

OLD class-attribute instance-attribute

OLD = 0

Algorithm in old versions

UNIFORM class-attribute instance-attribute

UNIFORM = 1

Uniform distribution

__call__

__call__() -> NoReturn
__call__(sigma: float) -> RandomAlgoWithInfo
__call__(*args: Any) -> Any
Source code
90
91
92
93
94
def __call__(self, *args: Any) -> Any:
    if self != RandomAlgo.GAUSSIAN:
        return TypeError

    return RandomAlgoWithInfo(self, *args)

RandomAlgoWithInfo

Bases: int

Attributes:

sigma instance-attribute

sigma: float

SampleMode

Bases: CustomIntEnum

Methods:

Attributes:

  • COLUMN

    Take 2 pixels as reference pixel. Reference pixels are in the same column of current pixel.

  • COL_ROW_MEAN

    Arithmetic mean of COLUMN and ROW. Reference points are randomly picked within the range.

  • MEAN_DIFF

    Similar to COL_ROW_MEAN, adds max/mid diff thresholds.

  • ROW

    Take 2 pixels as reference pixel. Reference pixels are in the same row of current pixel.

  • SQUARE

    Take 4 pixels as reference pixel. Reference pixels are in the square around current pixel.

COLUMN class-attribute instance-attribute

COLUMN = 1

Take 2 pixels as reference pixel. Reference pixels are in the same column of current pixel.

COL_ROW_MEAN class-attribute instance-attribute

COL_ROW_MEAN = 4

Arithmetic mean of COLUMN and ROW. Reference points are randomly picked within the range.

MEAN_DIFF class-attribute instance-attribute

MEAN_DIFF = 5

Similar to COL_ROW_MEAN, adds max/mid diff thresholds.

ROW class-attribute instance-attribute

ROW = 3

Take 2 pixels as reference pixel. Reference pixels are in the same row of current pixel.

SQUARE class-attribute instance-attribute

SQUARE = 2

Take 4 pixels as reference pixel. Reference pixels are in the square around current pixel.

__call__

__call__() -> NoReturn
__call__(
    thr_mid: int | list[int], thr_max: int | list[int]
) -> SampleModeMidDiffInfo
__call__(*args: Any) -> Any
Source code
53
54
55
56
57
def __call__(self, *args: Any) -> Any:
    if self != SampleMode.MEAN_DIFF:
        raise TypeError

    return SampleModeMidDiffInfo(self, *args)

SampleModeMidDiffInfo

Bases: NamedTuple

Attributes:

sample_mode instance-attribute

sample_mode: SampleMode

thr_max instance-attribute

thr_max: int | list[int]

thr_mid instance-attribute

thr_mid: int | list[int]