Created
June 2, 2022 22:08
-
-
Save wiwaz/173b964f871c7eaf5ac2534284028800 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import vapoursynth as vs | |
from havsfunc import Gauss, DitherLumaRebuild | |
import vsutil | |
core = vs.core | |
# Blur image and soften edges to assist in motion matching of edge blocks. Blocks are matched by SAD (sum of absolute differences between blocks), but even | |
# a slight change in an edge from frame to frame will give a high SAD due to the higher contrast of edges | |
def qtgmc_prefilter(clip: vs.VideoNode, SrchClipPP: int = 1, **dlrargs) -> vs.VideoNode: | |
bits = vsutil.get_depth(clip) | |
if SrchClipPP == 1: | |
spatialBlur = ( | |
clip.resize.Bilinear(clip.width // 2, clip.height // 2) | |
.std.Convolution(matrix=[1, 2, 1, 2, 4, 2, 1, 2, 1]) | |
.resize.Bilinear(clip.width, clip.height) | |
) | |
if SrchClipPP >= 2: | |
spatialBlur = Gauss( | |
clip.std.Convolution(matrix=[1, 2, 1, 2, 4, 2, 1, 2, 1]), p=2.35 | |
) | |
spatialBlur = core.std.Merge(spatialBlur, clip, weight=0.1) | |
if SrchClipPP == 3: | |
spatialBlur = core.std.Expr( | |
[spatialBlur, clip], | |
expr="x {i7} + y < x {i2} + x {i7} - y > x {i2} - x 51 * y 49 * + 100 / ? ?".format( | |
i7=vsutil.scale_value(7, 8, bits), i2=vsutil.scale_value(2, 8, bits) | |
), | |
) | |
srchClip = DitherLumaRebuild(spatialBlur, **dlrargs) | |
return srchClip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment