Skip to content

Instantly share code, notes, and snippets.

@noizuy
noizuy / lee_banding_mask.py
Created February 19, 2024 14:01
The very simple false contour mask from Ji Won Lee, Bo Ra Lim, Rae-Hong Park, Jae-Seung Kim and Wonseok Ahn, "Two-stage false contour detection using directional contrast and its application to adaptive false contour reduction," in IEEE Transactions on Consumer Electronics, vol. 52, no. 1, pp. 179-188, Feb. 2006, doi: 10.1109/TCE.2006.1605045.
from collections.abc import Callable
import vapoursynth as vs
core = vs.core
from vstools import depth, get_peak_value, get_lowest_value, get_y
def lee_banding_mask(clip: vs.VideoNode, bits: int = 2, threshold: int | None = None, edge_detection: Callable = core.std.Sobel):
"""
False contour detection via bit depth reduction. The idea is (overly) simple: Re-quantize and find difference to input, calculate the gradient, and mark gradients under a threshold as false contours.
Naturally, this only works on content that isn't naturally flat.
@noizuy
noizuy / fade_clipped.py
Last active September 12, 2024 09:29
>prot_val
import vapoursynth as vs
from vstools import depth, scale_value
core = vs.core
def fade_clipped(src: vs.VideoNode,
flt: vs.VideoNode,
lower: float = scale_value(16, 8, 32, scale_offsets=True),
upper: float = scale_value(235, 8, 32, scale_offsets=True),
amount: float = scale_value(10, 8, 32, scale_offsets=True)) -> vs.VideoNode:
diff_upper = f"{upper} x -"