Skip to content

utils

Functions:

normalize_thscd

normalize_thscd(
    thscd: int | tuple[int | None, int | float | None] | None,
    scale: bool = True,
) -> tuple[int | None, int | None]

Normalize and scale the thscd parameter.

Parameters:

  • thscd

    (int | tuple[int | None, int | float | None] | None) –

    thscd value to scale and/or normalize.

  • scale

    (bool, default: True ) –

    Whether to scale thscd2 from 0-100 percentage threshold to 0-255.

Returns:

  • tuple[int | None, int | None]

    Scaled and/or normalized thscd tuple.

Source code in vsdenoise/mvtools/utils.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def normalize_thscd(
    thscd: int | tuple[int | None, int | float | None] | None, scale: bool = True
) -> tuple[int | None, int | None]:
    """
    Normalize and scale the thscd parameter.

    Args:
        thscd: thscd value to scale and/or normalize.
        scale: Whether to scale thscd2 from 0-100 percentage threshold to 0-255.

    Returns:
        Scaled and/or normalized thscd tuple.
    """

    thscd1, thscd2 = thscd if isinstance(thscd, tuple) else (thscd, None)

    if scale and thscd2 is not None:
        thscd2 = round(thscd2 / 100 * 255)

    if isinstance(thscd2, float):
        thscd2 = int(thscd2)

    return (thscd1, thscd2)

planes_to_mvtools

planes_to_mvtools(input_planes: Sequence[int]) -> int

Convert a sequence of plane indices to MVTools' plane parameter value.

MVTools uses a single integer to represent which planes to process
  • 0: Process Y plane only
  • 1: Process U plane only
  • 2: Process V plane only
  • 3: Process UV planes only
  • 4: Process all planes

Parameters:

  • input_planes

    (Sequence[int]) –

    Sequence of plane indices (0=Y, 1=U, 2=V) to process.

Returns:

  • int

    Integer value used by MVTools to specify which planes to process.

Source code in vsdenoise/mvtools/utils.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def planes_to_mvtools(input_planes: Sequence[int]) -> int:
    """
    Convert a sequence of plane indices to MVTools' plane parameter value.

    MVTools uses a single integer to represent which planes to process:
        - 0: Process Y plane only
        - 1: Process U plane only
        - 2: Process V plane only
        - 3: Process UV planes only
        - 4: Process all planes

    Args:
        input_planes: Sequence of plane indices (0=Y, 1=U, 2=V) to process.

    Returns:
        Integer value used by MVTools to specify which planes to process.
    """

    planes = set(input_planes)

    if planes == {0, 1, 2}:
        return 4

    if len(planes) == 1 and planes.intersection({0, 1, 2}):
        return planes.pop()

    if planes == {1, 2}:
        return 3

    raise CustomValueError("Invalid planes specified!", planes_to_mvtools)