Skip to content

freqs

Classes:

MeanMode

Bases: CustomIntEnum

Methods:

Attributes:

ARITHMETIC class-attribute instance-attribute

ARITHMETIC = 1

CONTRAHARMONIC class-attribute instance-attribute

CONTRAHARMONIC = auto()

CUBIC class-attribute instance-attribute

CUBIC = 3

GEOMETRIC class-attribute instance-attribute

GEOMETRIC = 0

HARMONIC class-attribute instance-attribute

HARMONIC = -1

LEHMER class-attribute instance-attribute

LEHMER = auto()

MAXIMUM class-attribute instance-attribute

MAXIMUM = auto()

MEDIAN class-attribute instance-attribute

MEDIAN = auto()

MINIMUM class-attribute instance-attribute

MINIMUM = auto()

POWER class-attribute instance-attribute

POWER = auto()

RMS class-attribute instance-attribute

RMS = 2

__call__

__call__(
    *_clips: VideoNodeIterableT[VideoNode],
    p: float = ...,
    planes: PlanesT = None,
    func: FuncExceptT | None = None
) -> ConstantFormatVideoNode
__call__(
    *_clips: VideoNodeIterableT[VideoNode],
    planes: PlanesT = None,
    func: FuncExceptT | None = None
) -> ConstantFormatVideoNode
__call__(
    *_clips: VideoNodeIterableT[VideoNode],
    planes: PlanesT = None,
    func: FuncExceptT | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code in vsrgtools/freqs.py
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 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
def __call__(
    self,
    *_clips: VideoNodeIterableT[vs.VideoNode],
    planes: PlanesT = None,
    func: FuncExceptT | None = None,
    **kwargs: Any,
) -> ConstantFormatVideoNode:
    func = func or self.__class__

    clips = flatten_vnodes(_clips)

    assert check_variable_format(clips, func)

    n_clips = len(clips)
    all_clips = ExprVars(n_clips)

    if n_clips < 2:
        return next(iter(clips))

    match self:
        case MeanMode.POWER:
            p = kwargs.get("p", -1)
            return ExprOp.ADD(
                clips,
                suffix=f"neutral - {p} pow",
                expr_suffix=f"{n_clips} / {1 / p} pow neutral +",
                planes=planes,
                func=func,
            )

        case MeanMode.LEHMER:
            p = kwargs.get("p", 2)
            counts = range(n_clips)

            expr = StrList([[f"{clip} neutral - D{i}!" for i, clip in zip(counts, all_clips)]])
            for x in range(2):
                expr.extend([[f"D{i}@ {p - x} pow" for i in counts], ExprOp.ADD * (n_clips - 1)])

            return norm_expr(clips, f"{expr} / neutral +", planes, func=func)

        case MeanMode.HARMONIC | MeanMode.GEOMETRIC | MeanMode.RMS | MeanMode.CUBIC:
            return MeanMode.POWER(clips, p=self.value, planes=planes, func=func)

        case MeanMode.CONTRAHARMONIC:
            return MeanMode.LEHMER(clips, p=2, planes=planes, func=func)

        case MeanMode.ARITHMETIC:
            return ExprOp.ADD(clips, expr_suffix=f"{n_clips} /", planes=planes, func=func)

        case MeanMode.MINIMUM:
            return ExprOp.MIN(clips, planes=planes, func=func)

        case MeanMode.MAXIMUM:
            return ExprOp.MAX(clips, planes=planes, func=func)

        case MeanMode.MEDIAN:
            n_op = (n_clips - 1) // 2

            mean = "" if n_clips % 2 else "+ 2 /"

            return norm_expr(
                clips, f"{all_clips} sort{n_clips} drop{n_op} {mean} swap{n_op} drop{n_op}", planes, func=func
            )