Skip to content

enum

Classes:

Attributes:

ClenseModeT module-attribute

ClenseModeT = str | ClenseMode

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]
)

BilateralBackend

Bases: CustomStrEnum

Attributes:

CPU class-attribute instance-attribute

CPU = 'vszip'

GPU class-attribute instance-attribute

GPU = 'bilateralgpu'

GPU_RTC class-attribute instance-attribute

GPU_RTC = 'bilateralgpu_rtc'

BlurMatrix

Bases: CustomEnum

Methods:

Attributes:

BINOMIAL class-attribute instance-attribute

BINOMIAL = auto()

BOX_BLUR class-attribute instance-attribute

BOX_BLUR = MEAN

BOX_BLUR_NO_CENTER class-attribute instance-attribute

BOX_BLUR_NO_CENTER = MEAN_NO_CENTER

CIRCLE class-attribute instance-attribute

CIRCLE = MEAN_NO_CENTER

GAUSS class-attribute instance-attribute

GAUSS = auto()

LOG class-attribute instance-attribute

LOG = auto()

MEAN class-attribute instance-attribute

MEAN = auto()

MEAN_NO_CENTER class-attribute instance-attribute

MEAN_NO_CENTER = auto()

__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) -> BlurMatrixBase[int]
__call__(
    taps: int = 1, *, strength: float = 100.0, mode: ConvMode = HV
) -> BlurMatrixBase[float]
__call__(
    taps: int | None = None,
    *,
    sigma: float = 0.5,
    mode: ConvMode = HV,
    **kwargs: Any
) -> BlurMatrixBase[float]
__call__(taps: int | None = None, **kwargs: Any) -> Any
__call__(taps: int | None = None, **kwargs: Any) -> Any
Source code
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
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
443
def __call__(self, taps: int | None = None, **kwargs: Any) -> Any:
    kernel: BlurMatrixBase[Any]

    match self:
        case BlurMatrix.MEAN_NO_CENTER:
            taps = fallback(taps, 1)
            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:
            taps = fallback(taps, 1)
            mode = kwargs.pop("mode", ConvMode.SQUARE)

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

        case BlurMatrix.BINOMIAL:
            taps = fallback(taps, 1)
            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:
            taps = fallback(taps, 1)
            strength = kwargs.pop("strength", 100)
            mode = kwargs.pop("mode", ConvMode.HV)

            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)

        case BlurMatrix.GAUSS:
            taps = fallback(taps, 1)
            sigma = kwargs.pop("sigma", 0.5)
            mode = kwargs.pop("mode", ConvMode.HV)
            scale_value = kwargs.pop("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)

        case _:
            raise CustomNotImplementedError("Unsupported blur matrix enum!", self, self)

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

    return kernel

from_radius

from_radius(radius: int) -> BlurMatrixBase[float]
Source code
445
446
447
448
def from_radius(self: Literal[BlurMatrix.GAUSS], radius: int) -> BlurMatrixBase[float]:  # type: ignore[misc]
    assert self is BlurMatrix.GAUSS

    return BlurMatrix.GAUSS(None, sigma=(radius + 1.0) / 3)

get_taps

get_taps(sigma: float, taps: int | None = None) -> int
Source code
450
451
452
453
454
455
456
def get_taps(self: Literal[BlurMatrix.GAUSS], sigma: float, taps: int | None = None) -> int:  # type: ignore[misc]
    assert self is BlurMatrix.GAUSS

    if taps is None:
        taps = ceil(abs(sigma) * 8 + 1) // 2

    return taps

BlurMatrixBase

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

Bases: list[_Nb]

Methods:

  • __call__

    Performs a spatial or temporal convolution.

  • outer

Attributes:

Source code
168
169
170
171
172
def __init__(
    self, __iterable: Iterable[_Nb], /, mode: ConvMode = ConvMode.SQUARE,
) -> None:
    self.mode = mode
    super().__init__(__iterable)

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
) -> ConstantFormatVideoNode

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:

  • ConstantFormatVideoNode

    Processed clip.

Source code
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
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
) -> ConstantFormatVideoNode:
    """
    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.
    """
    assert check_variable(clip, self)

    if len(self) <= 1:
        return clip

    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
308
309
310
311
def outer(self) -> Self:
    from numpy import outer

    return self.__class__(list[_Nb](outer(self, self).flatten()), self.mode)  #pyright: ignore[reportArgumentType]

ClenseMode

Bases: CustomStrEnum

Methods:

Attributes:

BACKWARD class-attribute instance-attribute

BACKWARD = 'BackwardClense'

BOTH class-attribute instance-attribute

BOTH = 'Clense'

FORWARD class-attribute instance-attribute

FORWARD = 'ForwardClense'

NONE class-attribute instance-attribute

NONE = ''

__call__

__call__(
    clip: VideoNode,
    previous_clip: VideoNode | None = None,
    next_clip: VideoNode | None = None,
    planes: PlanesT = None,
) -> ConstantFormatVideoNode
Source code
151
152
153
154
155
156
157
158
159
def __call__(
    self,
    clip: vs.VideoNode,
    previous_clip: vs.VideoNode | None = None,
    next_clip: vs.VideoNode | None = None,
    planes: PlanesT = None
) -> ConstantFormatVideoNode:
    from .rgtools import clense
    return clense(clip, previous_clip, next_clip, self, planes)

LimitFilterMode

Bases: LimitFilterModeMeta, CustomIntEnum

Two sources, one filtered

Methods:

Attributes:

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) -> Self
Source code
46
47
48
49
def __call__(self, force_expr: bool = True) -> Self:
    self.force_expr = force_expr

    return self

LimitFilterModeMeta

Attributes:

force_expr class-attribute instance-attribute

force_expr = True

RemoveGrainMode

Bases: CustomIntEnum

Methods:

Attributes:

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 = MEAN

BOX_BLUR_NO_CENTER class-attribute instance-attribute

BOX_BLUR_NO_CENTER = MEAN_NO_CENTER

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

MEAN class-attribute instance-attribute

MEAN = 20

MEAN_NO_CENTER class-attribute instance-attribute

MEAN_NO_CENTER = 19

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

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) -> ConstantFormatVideoNode
Source code
83
84
85
86
def __call__(self, clip: vs.VideoNode, planes: PlanesT = None) -> ConstantFormatVideoNode:
    from .rgtools import remove_grain
    from .util import norm_rmode_planes
    return remove_grain(clip, norm_rmode_planes(clip, self, planes))

RepairMode

Bases: CustomIntEnum

Methods:

Attributes:

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
) -> ConstantFormatVideoNode
Source code
122
123
124
125
def __call__(self, clip: vs.VideoNode, repairclip: vs.VideoNode, planes: PlanesT = None) -> ConstantFormatVideoNode:
    from .rgtools import repair
    from .util import norm_rmode_planes
    return repair(clip, repairclip, norm_rmode_planes(clip, self, planes))

VerticalCleanerMode

Bases: CustomIntEnum

Methods:

Attributes:

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) -> ConstantFormatVideoNode
Source code
136
137
138
139
def __call__(self, clip: vs.VideoNode, planes: PlanesT = None) -> ConstantFormatVideoNode:
    from .rgtools import vertical_cleaner
    from .util import norm_rmode_planes
    return vertical_cleaner(clip, norm_rmode_planes(clip, self, planes))