Skip to content

mask

Functions:

  • base_dehalo_mask

    Based on muvsfunc.YAHRmask, stand-alone version with some tweaks. Adopted from jvsfunc.

base_dehalo_mask

base_dehalo_mask(
    src: VideoNode,
    expand: float = 0.5,
    iterations: int = 2,
    brz0: float = 0.31,
    brz1: float = 1.0,
    shift: int = 8,
    pre_ss: bool = True,
    multi: float = 1.0,
) -> VideoNode

Based on muvsfunc.YAHRmask, stand-alone version with some tweaks. Adopted from jvsfunc.

Parameters:

  • src

    (VideoNode) –

    Input clip.

  • expand

    (float, default: 0.5 ) –

    Expansion of edge mask.

  • iterations

    (int, default: 2 ) –

    Protects parallel lines and corners that are usually damaged by strong dehaloing.

  • brz0

    (float, default: 0.31 ) –

    Adjusts the internal line thickness.

  • brz1

    (float, default: 1.0 ) –

    Adjusts the internal line thickness.

  • shift

    (int, default: 8 ) –

    8-bit corrective shift value for fine-tuning expansion.

  • pre_ss

    (bool, default: True ) –

    Perform the mask creation at 2x.

  • multi

    (float, default: 1.0 ) –

    Final pixel value multiplier.

Returns:

  • VideoNode

    Dehalo mask.

Source code
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def base_dehalo_mask(
    src: vs.VideoNode, expand: float = 0.5, iterations: int = 2,
    brz0: float = 0.31, brz1: float = 1.0, shift: int = 8,
    pre_ss: bool = True, multi: float = 1.0
) -> vs.VideoNode:
    """
    Based on `muvsfunc.YAHRmask`, stand-alone version with some tweaks. Adopted from jvsfunc.

    :param src:         Input clip.
    :param expand:      Expansion of edge mask.
    :param iterations:  Protects parallel lines and corners that are usually damaged by strong dehaloing.
    :param brz0:        Adjusts the internal line thickness.
    :param brz1:        Adjusts the internal line thickness.
    :param shift:       8-bit corrective shift value for fine-tuning expansion.
    :param pre_ss:      Perform the mask creation at 2x.
    :param multi:       Final pixel value multiplier.

    :return:            Dehalo mask.
    """

    assert check_progressive(src, base_dehalo_mask)

    luma = get_y(src)

    if pre_ss:
        luma = Nnedi3.scale(luma, luma.width * 2, luma.height * 2)

    exp_edges = norm_expr(
        [luma, Morpho.maximum(luma, iterations=2)], 'y x - {shift} - range_half *',
        shift=scale_delta(shift, 8, luma), func=base_dehalo_mask
    )

    edgemask = PrewittTCanny.edgemask(exp_edges, sigma=sqrt(expand * 2), mode=-1, multi=16)

    halo_mask = Morpho.maximum(exp_edges, iterations=iterations)
    halo_mask = Morpho.minimum(halo_mask, iterations=iterations)
    halo_mask = Morpho.binarize(halo_mask, brz0, 1.0, 0.0)

    if brz1 != 1.0:
        halo_mask = Morpho.inflate(halo_mask, iterations=2)
        halo_mask = Morpho.binarize(halo_mask, brz1)

    mask = norm_expr(
        [edgemask, BlurMatrix.BINOMIAL()(halo_mask)], 'x y min {multi} *', multi=multi, func=base_dehalo_mask
    )

    if pre_ss:
        return Point.scale(mask, src.width, src.height)

    return mask