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.

IndexLike

IndexLike = SupportsIndex | slice

NoneSlice

NoneSlice = slice | None

FixBorderBrightness

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

Bases: VSObject

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

Example
# The following example darkens the top and right borders slightly (0.9x)
# to reduce edge brightness inconsistencies, then applies the correction.

fbb = FixBorderBrightness(clip)
fbb.fix_row(-2, 0.9)  # Adjust brightness near the bottom edge
fbb.fix_row(1, 0.9)  # Adjust brightness near the top edge
fbb.fix_column(1, 0.9)  # Adjust brightness near the left edge
fbb.fix_column(-2, 0.9)  # Adjust brightness near the right edge
out = fbb.process()  # Apply all configured border corrections

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
 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
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.
    """
    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
233
234
235
236
237
238
239
240
241
242
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
244
245
246
247
248
249
250
251
252
253
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
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
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
    )