Skip to content

enum

RemoveGrainModeT module-attribute

RemoveGrainModeT = int | RemoveGrainMode | Sequence[int | RemoveGrainMode]

RepairModeT module-attribute

RepairModeT = int | RepairMode | Sequence[int | RepairMode]

VerticalCleanerModeT module-attribute

VerticalCleanerModeT = (
    int | VerticalCleanerMode | Sequence[int | VerticalCleanerMode]
)

BlurMatrix

Bases: CustomIntEnum

BINOMIAL class-attribute instance-attribute

BINOMIAL = 2

CIRCLE class-attribute instance-attribute

CIRCLE = 0

LOG class-attribute instance-attribute

LOG = 3

MEAN class-attribute instance-attribute

MEAN = 1

GAUSS

__call__

__call__(
    taps: int | None = None,
    *,
    sigma: float = 0.5,
    mode: ConvMode = HV,
    **kwargs: Any
) -> BlurMatrixBase[float]
Source code
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
def __call__(
    self,
    taps: int | None = None,
    *,
    sigma: float = 0.5,
    mode: ConvMode = ConvMode.HV,
    **kwargs: Any
) -> BlurMatrixBase[float]:
    scale_value = kwargs.get("scale_value", 1023)

    if mode == ConvMode.SQUARE:
        scale_value = sqrt(scale_value)

    taps = self.get_taps(sigma, taps)

    if taps < 0:
        raise CustomValueError('Taps must be >= 0!')

    if sigma > 0.0:
        half_pisqrt = 1.0 / sqrt(2.0 * pi) * sigma
        doub_qsigma = 2 * sigma ** 2

        high, *mat = [half_pisqrt * exp(-x ** 2 / doub_qsigma) for x in range(taps + 1)]

        mat = [x * scale_value / high for x in mat]
        mat = [*mat[::-1], scale_value, *mat]
    else:
        mat = [scale_value]

    kernel = BlurMatrixBase(mat, mode)

    if mode == ConvMode.SQUARE:
        kernel = kernel.outer()

    return kernel

from_radius

from_radius(radius: int) -> BlurMatrixBase[float]
Source code
359
360
def from_radius(self, radius: int) -> BlurMatrixBase[float]:
    return self(None, sigma=(radius + 1.0) / 3)

get_taps staticmethod

get_taps(sigma: float, taps: int | None = None) -> int
Source code
362
363
364
365
366
367
@staticmethod
def get_taps(sigma: float, taps: int | None = None) -> int:
    if taps is None:
        taps = ceil(abs(sigma) * 8 + 1) // 2

    return taps

__call__

__call__(taps: int = 1, *, mode: ConvMode = SQUARE) -> BlurMatrixBase[int]
__call__(taps: int = 1, *, mode: ConvMode = SQUARE) -> BlurMatrixBase[int]
__call__(
    taps: int = 1, *, mode: ConvMode = HV, **kwargs: Any
) -> BlurMatrixBase[int]
__call__(
    taps: int = 1, *, strength: float = 100.0, mode: ConvMode = HV
) -> BlurMatrixBase[float]
__call__(taps: int = 1, **kwargs: Any) -> Any
Source code
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
def __call__(self, taps: int = 1, **kwargs: Any) -> Any:
    kernel: BlurMatrixBase[Any]

    match self:
        case BlurMatrix.CIRCLE:
            mode = kwargs.pop("mode", ConvMode.SQUARE)

            matrix = [1 for _ in range(((2 * taps + 1) ** (2 if mode == ConvMode.SQUARE else 1)) - 1)]
            matrix.insert(len(matrix) // 2, 0)

            return BlurMatrixBase[int](matrix, mode)

        case BlurMatrix.MEAN:
            mode = kwargs.pop("mode", ConvMode.SQUARE)

            kernel = BlurMatrixBase[int]([1 for _ in range(((2 * taps + 1)))], mode)

        case BlurMatrix.BINOMIAL:
            mode = kwargs.pop("mode", ConvMode.HV)

            c = 1
            n = taps * 2 + 1

            matrix = list[int]()

            for i in range(1, taps + 2):
                matrix.append(c)
                c = c * (n - i) // i

            kernel = BlurMatrixBase(matrix[:-1] + matrix[::-1], mode)

        case BlurMatrix.LOG:
            mode = kwargs.pop("mode", ConvMode.HV)
            strength = kwargs.get("strength", 100)

            strength = max(1e-6, min(log2(3) * strength / 100, log2(3)))

            weight = 0.5 ** strength / ((1 - 0.5 ** strength) * 0.5)

            matrixf = [1.0]

            for _ in range(taps):
                matrixf.append(matrixf[-1] / weight)

            kernel = BlurMatrixBase([*matrixf[::-1], *matrixf[1:]], mode)

    if mode == ConvMode.SQUARE:
        kernel = kernel.outer()

    return kernel

BlurMatrixBase

BlurMatrixBase(__iterable: Iterable[Nb], /, mode: ConvMode = SQUARE)

Bases: list[Nb]

Source code
144
145
146
147
148
def __init__(
    self, __iterable: Iterable[Nb], /, mode: ConvMode = ConvMode.SQUARE,
) -> None:
    self.mode = mode
    super().__init__(__iterable)  # type: ignore[arg-type]

mode instance-attribute

mode = mode

__call__

__call__(
    clip: VideoNode,
    planes: PlanesT = None,
    bias: float | None = None,
    divisor: float | None = None,
    saturate: bool = True,
    passes: int = 1,
    expr_kwargs: KwargsT | None = None,
    **conv_kwargs: Any
) -> VideoNode

Performs a spatial or temporal convolution. It will either calls std.Convolution, std.AverageFrames or ExprOp.convolution based on the ConvMode mode picked.

Parameters:

  • clip

    (VideoNode) –

    Clip to process.

  • planes

    (PlanesT, default: None ) –

    Specifies which planes will be processed.

  • bias

    (float | None, default: None ) –

    Value to add to the final result of the convolution (before clamping the result to the format's range of valid values).

  • divisor

    (float | None, default: None ) –

    Divide the output of the convolution by this value (before adding bias). The default is the sum of the elements of the matrix

  • saturate

    (bool, default: True ) –

    If True, negative values become 0. If False, absolute values are returned.

  • passes

    (int, default: 1 ) –

    Number of iterations.

  • expr_kwargs

    (KwargsT | None, default: None ) –

    A KwargsT of keyword arguments for ExprOp.convolution.call when it is picked.

  • **conv_kwargs

    (Any, default: {} ) –

    Additional keyword arguments for std.Convolution, std.AverageFrames or ExprOp.convolution.

Returns:

  • VideoNode

    Processed clip.

Source code
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
203
204
def __call__(
    self, clip: vs.VideoNode, planes: PlanesT = None,
    bias: float | None = None, divisor: float | None = None, saturate: bool = True,
    passes: int = 1, expr_kwargs: KwargsT | None = None, **conv_kwargs: Any
) -> vs.VideoNode:
    """
    Performs a spatial or temporal convolution.
    It will either calls std.Convolution, std.AverageFrames or ExprOp.convolution
    based on the ConvMode mode picked.

    :param clip:            Clip to process.
    :param planes:          Specifies which planes will be processed.
    :param bias:            Value to add to the final result of the convolution
                            (before clamping the result to the format's range of valid values).
    :param divisor:         Divide the output of the convolution by this value (before adding bias).
                            The default is the sum of the elements of the matrix
    :param saturate:        If True, negative values become 0.
                            If False, absolute values are returned.
    :param passes:          Number of iterations.
    :param expr_kwargs:     A KwargsT of keyword arguments for ExprOp.convolution.__call__ when it is picked.
    :param **conv_kwargs:   Additional keyword arguments for std.Convolution, std.AverageFrames or ExprOp.convolution.

    :return:                Processed clip.
    """
    if len(self) <= 1:
        return clip

    assert (check_variable(clip, self.__call__))

    expr_kwargs = expr_kwargs or KwargsT()

    fp16 = clip.format.sample_type == vs.FLOAT and clip.format.bits_per_sample == 16

    if self.mode.is_spatial:
        # std.Convolution is limited to 25 numbers
        # SQUARE mode is not optimized
        # std.Convolution doesn't support float 16
        if len(self) <= 25 and self.mode != ConvMode.SQUARE and not fp16:
            return iterate(clip, core.std.Convolution, passes, self, bias, divisor, planes, saturate, self.mode)

        return iterate(
            clip, ExprOp.convolution("x", self, bias, fallback(divisor, True), saturate, self.mode, **conv_kwargs),
            passes, planes=planes, **expr_kwargs
        )

    if all([
        not fp16,
        len(self) <= 31,
        not bias,
        saturate,
        (len(conv_kwargs) == 0 or (len(conv_kwargs) == 1 and "scenechange" in conv_kwargs))
    ]):
        return iterate(clip, core.std.AverageFrames, passes, self, divisor, planes=planes, **conv_kwargs)

    return self._averageframes_akarin(clip, planes, bias, divisor, saturate, passes, expr_kwargs, **conv_kwargs)

outer

outer() -> Self
Source code
309
310
311
312
def outer(self) -> Self:
    from numpy import outer

    return self.__class__(outer(self, self).flatten().tolist(), self.mode)

LimitFilterMode

Bases: LimitFilterModeMeta, CustomIntEnum

Two sources, one filtered

CLAMPING class-attribute instance-attribute

CLAMPING = auto()

DIFF_MAX class-attribute instance-attribute

DIFF_MAX = auto()

One/Two sources, one filtered

DIFF_MIN class-attribute instance-attribute

DIFF_MIN = auto()

SIMPLE2_MAX class-attribute instance-attribute

SIMPLE2_MAX = auto()

SIMPLE2_MIN class-attribute instance-attribute

SIMPLE2_MIN = auto()

SIMPLE_MAX class-attribute instance-attribute

SIMPLE_MAX = auto()

One source, two filtered

SIMPLE_MIN class-attribute instance-attribute

SIMPLE_MIN = auto()

force_expr class-attribute instance-attribute

force_expr = True

op property

op: str

__call__

__call__(force_expr: bool = True) -> LimitFilterMode
Source code
45
46
47
48
def __call__(self, force_expr: bool = True) -> LimitFilterMode:
    self.force_expr = force_expr

    return self

LimitFilterModeMeta

force_expr class-attribute instance-attribute

force_expr = True

RemoveGrainMode

Bases: CustomIntEnum

BINOMIAL_BLUR class-attribute instance-attribute

BINOMIAL_BLUR = 11

BOB_BOTTOM_CLOSE class-attribute instance-attribute

BOB_BOTTOM_CLOSE = 14

BOB_BOTTOM_INTER class-attribute instance-attribute

BOB_BOTTOM_INTER = 16

BOB_TOP_CLOSE class-attribute instance-attribute

BOB_TOP_CLOSE = 13

BOB_TOP_INTER class-attribute instance-attribute

BOB_TOP_INTER = 15

BOX_BLUR class-attribute instance-attribute

BOX_BLUR = 20

BOX_BLUR_NO_CENTER class-attribute instance-attribute

BOX_BLUR_NO_CENTER = 19

EDGE_CLIP_LIGHT class-attribute instance-attribute

EDGE_CLIP_LIGHT = 8

EDGE_CLIP_MEDIUM class-attribute instance-attribute

EDGE_CLIP_MEDIUM = 7

EDGE_CLIP_MODERATE class-attribute instance-attribute

EDGE_CLIP_MODERATE = 6

EDGE_CLIP_STRONG class-attribute instance-attribute

EDGE_CLIP_STRONG = 5

EDGE_DEHALO class-attribute instance-attribute

EDGE_DEHALO = 23

EDGE_DEHALO2 class-attribute instance-attribute

EDGE_DEHALO2 = 24

LINE_CLIP_CLOSE class-attribute instance-attribute

LINE_CLIP_CLOSE = 9

LINE_CLIP_OPP class-attribute instance-attribute

LINE_CLIP_OPP = 18

MINMAX_AROUND1 class-attribute instance-attribute

MINMAX_AROUND1 = 1

MINMAX_AROUND2 class-attribute instance-attribute

MINMAX_AROUND2 = 2

MINMAX_AROUND3 class-attribute instance-attribute

MINMAX_AROUND3 = 3

MINMAX_MEDIAN class-attribute instance-attribute

MINMAX_MEDIAN = 4

MINMAX_MEDIAN_OPP class-attribute instance-attribute

MINMAX_MEDIAN_OPP = 17

MIN_SHARP class-attribute instance-attribute

MIN_SHARP = 10

MIN_SHARP2 class-attribute instance-attribute

MIN_SHARP2 = 25

NONE class-attribute instance-attribute

NONE = 0

OPP_CLIP_AVG class-attribute instance-attribute

OPP_CLIP_AVG = 21

OPP_CLIP_AVG_FAST class-attribute instance-attribute

OPP_CLIP_AVG_FAST = 22

SMART_RGC class-attribute instance-attribute

SMART_RGC = 26

SMART_RGCL class-attribute instance-attribute

SMART_RGCL = 27

SMART_RGCL2 class-attribute instance-attribute

SMART_RGCL2 = 28

__call__

__call__(clip: VideoNode, planes: PlanesT = None) -> VideoNode
Source code
81
82
83
84
def __call__(self, clip: vs.VideoNode, planes: PlanesT = None) -> vs.VideoNode:
    from .rgtools import removegrain
    from .util import norm_rmode_planes
    return removegrain(clip, norm_rmode_planes(clip, self, planes))

RepairMode

Bases: CustomIntEnum

CLIP_REF_RG17 class-attribute instance-attribute

CLIP_REF_RG17 = 17

CLIP_REF_RG18 class-attribute instance-attribute

CLIP_REF_RG18 = 18

CLIP_REF_RG19 class-attribute instance-attribute

CLIP_REF_RG19 = 19

CLIP_REF_RG20 class-attribute instance-attribute

CLIP_REF_RG20 = 20

CLIP_REF_RG21 class-attribute instance-attribute

CLIP_REF_RG21 = 21

CLIP_REF_RG22 class-attribute instance-attribute

CLIP_REF_RG22 = 22

CLIP_REF_RG23 class-attribute instance-attribute

CLIP_REF_RG23 = 23

CLIP_REF_RG24 class-attribute instance-attribute

CLIP_REF_RG24 = 24

CLIP_REF_RG26 class-attribute instance-attribute

CLIP_REF_RG26 = 26

CLIP_REF_RG27 class-attribute instance-attribute

CLIP_REF_RG27 = 27

CLIP_REF_RG28 class-attribute instance-attribute

CLIP_REF_RG28 = 28

CLIP_REF_RG5 class-attribute instance-attribute

CLIP_REF_RG5 = 15

CLIP_REF_RG6 class-attribute instance-attribute

CLIP_REF_RG6 = 16

LINE_CLIP_CLOSE class-attribute instance-attribute

LINE_CLIP_CLOSE = 9

LINE_CLIP_LIGHT class-attribute instance-attribute

LINE_CLIP_LIGHT = 6

LINE_CLIP_MEDIUM class-attribute instance-attribute

LINE_CLIP_MEDIUM = 7

LINE_CLIP_MIN class-attribute instance-attribute

LINE_CLIP_MIN = 5

LINE_CLIP_STRONG class-attribute instance-attribute

LINE_CLIP_STRONG = 8

MINMAX_SQUARE1 class-attribute instance-attribute

MINMAX_SQUARE1 = 1

MINMAX_SQUARE2 class-attribute instance-attribute

MINMAX_SQUARE2 = 2

MINMAX_SQUARE3 class-attribute instance-attribute

MINMAX_SQUARE3 = 3

MINMAX_SQUARE4 class-attribute instance-attribute

MINMAX_SQUARE4 = 4

MINMAX_SQUARE_REF1 class-attribute instance-attribute

MINMAX_SQUARE_REF1 = 11

MINMAX_SQUARE_REF2 class-attribute instance-attribute

MINMAX_SQUARE_REF2 = 12

MINMAX_SQUARE_REF3 class-attribute instance-attribute

MINMAX_SQUARE_REF3 = 13

MINMAX_SQUARE_REF4 class-attribute instance-attribute

MINMAX_SQUARE_REF4 = 14

MINMAX_SQUARE_REF_CLOSE class-attribute instance-attribute

MINMAX_SQUARE_REF_CLOSE = 10

NONE class-attribute instance-attribute

NONE = 0

__call__

__call__(
    clip: VideoNode, repairclip: VideoNode, planes: PlanesT = None
) -> VideoNode
Source code
120
121
122
123
def __call__(self, clip: vs.VideoNode, repairclip: vs.VideoNode, planes: PlanesT = None) -> vs.VideoNode:
    from .rgtools import repair
    from .util import norm_rmode_planes
    return repair(clip, repairclip, norm_rmode_planes(clip, self, planes))

VerticalCleanerMode

Bases: CustomIntEnum

MEDIAN class-attribute instance-attribute

MEDIAN = 1

NONE class-attribute instance-attribute

NONE = 0

PRESERVING class-attribute instance-attribute

PRESERVING = 2

__call__

__call__(clip: VideoNode, planes: PlanesT = None) -> VideoNode
Source code
134
135
136
137
def __call__(self, clip: vs.VideoNode, planes: PlanesT = None) -> vs.VideoNode:
    from .rgtools import vertical_cleaner
    from .util import norm_rmode_planes
    return vertical_cleaner(clip, norm_rmode_planes(clip, self, planes))