Skip to content

border

This module implements utilities for correcting dirty or damaged borders.

Classes:

  • FixBorderBrightness

    Utility class to adjust or correct brightness inconsistencies along clip borders.

Attributes:

IndexLike module-attribute

NoneSlice module-attribute

NoneSlice: TypeAlias = slice[None, None, None] | None

FixBorderBrightness

FixBorderBrightness(
    clip: VideoNode,
    protect: bool | tuple[float, float] | list[tuple[float, float]] = True,
)

Bases: vs_object

Utility class to adjust or correct brightness inconsistencies along clip borders.

Initializes the class.

Parameters:

  • clip

    (VideoNode) –

    Input clip.

  • protect

    (bool | tuple[float, float] | list[tuple[float, float]], default: True ) –

    Protection configuration for pixel intensity ranges.

    • If True, automatically determines safe low/high protection thresholds per plane using the clip's minimum and maximum allowed pixel values.
    • If False, disables protection (no clipping protection is applied).
    • If a tuple (low, high) is given, applies it as a protection range.
    • If a list of tuples is provided, applies individual protection ranges per plane.

Methods:

  • fix_column

    Apply a correction multiplier to an entire column in a specific plane.

  • fix_row

    Apply a correction multiplier to an entire row in a specific plane.

  • process

    Apply all configured border corrections to the clip.

Attributes:

Source code in vsdehalo/border.py
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
def __init__(
    self, clip: vs.VideoNode, protect: bool | tuple[float, float] | list[tuple[float, float]] = True
) -> None:
    """
    Initializes the class.

    Args:
        clip: Input clip.
        protect: Protection configuration for pixel intensity ranges.

               - If `True`, automatically determines safe low/high protection thresholds
                 per plane using the clip's minimum and maximum allowed pixel values.
               - If `False`, disables protection (no clipping protection is applied).
               - If a tuple `(low, high)` is given, applies it as a protection range.
               - If a list of tuples is provided, applies individual protection ranges per plane.
    """
    assert check_variable_format(clip, self.__class__)
    self.clip = clip

    ws, hs = zip(*((w, h) for _, w, h in get_resolutions(clip)))

    self._tofix_columns = {i: _BorderDict(w) for i, w in enumerate(ws)}
    self._tofix_rows = {i: _BorderDict(h) for i, h in enumerate(hs)}

    if protect is True:
        protect = [(low, hight) for low, hight in zip(get_lowest_values(clip), get_peak_values(clip))]
    elif protect is False:
        protect = [(False, False)]
    elif isinstance(protect, tuple):
        protect = [protect]

    self._protect = normalize_seq(protect, clip.format.num_planes)

clip instance-attribute

clip = clip

fix_column

fix_column(num: int, value: float, plane_index: int = 0) -> None

Apply a correction multiplier to an entire column in a specific plane.

Parameters:

  • num

    (int) –

    Column index to correct.

  • value

    (float) –

    Correction value.

  • plane_index

    (int, default: 0 ) –

    Plane index to apply the correction to (default is 0).

Source code in vsdehalo/border.py
215
216
217
218
219
220
221
222
223
224
def fix_column(self, num: int, value: float, plane_index: int = 0) -> None:
    """
    Apply a correction multiplier to an entire column in a specific plane.

    Args:
        num: Column index to correct.
        value: Correction value.
        plane_index: Plane index to apply the correction to (default is 0).
    """
    self[num, :, plane_index] = value

fix_row

fix_row(num: int, value: float, plane_index: int = 0) -> None

Apply a correction multiplier to an entire row in a specific plane.

Parameters:

  • num

    (int) –

    Row index to correct.

  • value

    (float) –

    Correction value.

  • plane_index

    (int, default: 0 ) –

    Plane index to apply the correction to (default is 0).

Source code in vsdehalo/border.py
226
227
228
229
230
231
232
233
234
235
def fix_row(self, num: int, value: float, plane_index: int = 0) -> None:
    """
    Apply a correction multiplier to an entire row in a specific plane.

    Args:
        num: Row index to correct.
        value: Correction value.
        plane_index: Plane index to apply the correction to (default is 0).
    """
    self[:, num, plane_index] = value

process

process(**kwargs: Any) -> VideoNode

Apply all configured border corrections to the clip.

Parameters:

Returns:

  • VideoNode

    A new clip with fixed borders applied.

Source code in vsdehalo/border.py
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
def process(self, **kwargs: Any) -> vs.VideoNode:
    """
    Apply all configured border corrections to the clip.

    Args:
        **kwargs: Additional arguments forwarded to [vsexprtools.norm_expr][].

    Returns:
        A new clip with fixed borders applied.
    """
    exprs = list[ExprList]()

    for i, (columns, rows, protect) in enumerate(
        zip(self._tofix_columns.values(), self._tofix_rows.values(), self._protect)
    ):
        expr = ExprList()

        if not rows and not columns:
            exprs.append(expr)
            continue

        norm = ExprToken.PlaneMin if i == 0 or self.clip.format.color_family == vs.RGB else ExprToken.Neutral

        expr.append(f"x {norm} - CLIP!")

        if columns:
            for num, value in columns.items():
                expr.append("X", num, "=", "CLIP@", value, "*")
            expr.append("CLIP@", ExprOp.TERN * len(columns), "CLIP!")

        if rows:
            for num, value in rows.items():
                expr.append("Y", num, "=", "CLIP@", value, "*")
            expr.append("CLIP@", ExprOp.TERN * len(rows), "CLIP!")

        expr.append("CLIP@", norm, "+")

        if any(protect):
            expr = ExprList(["x", "{protect_lo}", ">", "x", "{protect_hi}", "<", "and", expr, "x", "?"])

        exprs.append(expr)

    protect_lo, protect_hi = zip(*self._protect)

    return norm_expr(
        self.clip, tuple(exprs), func=self.__class__, **kwargs, protect_lo=protect_lo, protect_hi=protect_hi
    )