5
0

common: antialiasing tweaks

This commit is contained in:
louis f 2021-04-23 23:05:01 -04:00
parent eefc597138
commit 4f5a6d9044
Signed by: louis
GPG Key ID: 44D7E1DE4E23D6F2
8 changed files with 53 additions and 50 deletions

1
.gitignore vendored
View File

@ -21,3 +21,4 @@ ffmpeg2pass*.log
**/.vspreview/
**/results/
**/__pycache__/
**/*.egg-info/

View File

@ -1,5 +1,8 @@
import vapoursynth as vs
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise,
finalize, fsrcnnx_rescale, letterbox_edgefix)
from yt_common.automation import SelfRunner
from yt_common.source import waka_replace
@ -9,11 +12,6 @@ from lvsfunc.dehardsub import HardsubSign, HardsubMask, bounded_dehardsub
from typing import List
import os
import sys
sys.path.append("..")
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise, # noqa: E402
finalize, fsrcnnx_rescale, letterbox_edgefix)
core = vs.core

View File

@ -1,5 +1,8 @@
import vapoursynth as vs
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise, finalize,
fsrcnnx_rescale)
from yt_common.automation import SelfRunner
from yt_common.source import waka_replace
@ -9,11 +12,6 @@ from lvsfunc.dehardsub import HardsubMask, HardsubSign, bounded_dehardsub
from typing import List
import os
import sys
sys.path.append("..")
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise, finalize, # noqa: E402
fsrcnnx_rescale)
core = vs.core

View File

@ -1,5 +1,8 @@
import vapoursynth as vs
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise,
finalize, fsrcnnx_rescale, letterbox_edgefix)
from yt_common.automation import SelfRunner
from yt_common.source import waka_replace
@ -9,11 +12,6 @@ from lvsfunc.dehardsub import HardsubMask, HardsubLine, HardsubSign, bounded_deh
from typing import List
import os
import sys
sys.path.append("..")
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise, # noqa: E402
finalize, fsrcnnx_rescale, letterbox_edgefix)
core = vs.core

View File

@ -1,5 +1,8 @@
import vapoursynth as vs
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise,
finalize, fsrcnnx_rescale, letterbox_edgefix)
from yt_common.automation import SelfRunner
from yt_common.source import waka_replace
@ -9,11 +12,6 @@ from lvsfunc.dehardsub import HardsubLine, HardsubSign, HardsubMask, bounded_deh
from typing import List
import os
import sys
sys.path.append("..")
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise, # noqa: E402
finalize, fsrcnnx_rescale, letterbox_edgefix)
core = vs.core

25
Vivy/setup.py Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
import setuptools
name = "vivy_common"
version = "0.0.0"
release = "0.0.0"
setuptools.setup(
name=name,
version=release,
author="louis",
author_email="louis@poweris.moe",
description="yametetomete vivy common module",
packages=["vivy_common"],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
package_data={
'vivy_common': ['py.typed', 'workraw-settings', 'final-settings', 'shaders/FSRCNNX_x2_56-16-4-1.glsl'],
},
python_requires='>=3.8',
)

View File

@ -49,7 +49,7 @@ def deband(clip: vs.VideoNode) -> vs.VideoNode:
def antialias(clip: vs.VideoNode, noaa: Optional[List[Range]] = None) -> vs.VideoNode:
clamp = antialiasing.sraa_clamp(clip, mask=antialiasing.aa_mask_strong(clip))
clamp = antialiasing.sraa_clamp(clip, mask=antialiasing.mask_strong(clip))
return lvf.misc.replace_ranges(clamp, clip, noaa) if noaa else clamp

View File

@ -2,34 +2,19 @@ import vapoursynth as vs
import vsutil
from kagefunc import kirsch
from lvsfunc.aa import clamp_aa, upscaled_sraa
from havsfunc import SMDegrain
from lvsfunc.aa import nnedi3, clamp_aa, upscaled_sraa
from lvsfunc.kernels import Bicubic
from lvsfunc.misc import replace_ranges, scale_thresh
from lvsfunc.types import Range
from typing import Any, Dict, List, Optional, Union
from typing import Callable, List, Optional, Union
core = vs.core
def nnedi3(clip: vs.VideoNode, opencl: bool = False) -> vs.VideoNode:
nnedi3_args: Dict[str, Any] = dict(field=0, dh=True, nsize=3, nns=3, qual=1)
y = vsutil.get_y(clip)
def _nnedi3(clip: vs.VideoNode) -> vs.VideoNode:
return clip.nnedi3cl.NNEDI3CL(**nnedi3_args) if opencl \
else clip.nnedi3.nnedi3(**nnedi3_args)
aa = _nnedi3(y.std.Transpose())
aa = aa.resize.Spline36(height=clip.width, src_top=0.5).std.Transpose()
aa = _nnedi3(aa)
aa = aa.resize.Spline36(height=clip.height, src_top=0.5)
return aa
def aa_mask_weak(clip: vs.VideoNode) -> vs.VideoNode:
def mask_weak(clip: vs.VideoNode) -> vs.VideoNode:
# use bilateral to smear the noise as much as possible without destroying lines
pre = vsutil.get_y(clip).bilateral.Bilateral(sigmaS=5, sigmaR=0.75)
# frei-chen edge detection
@ -39,20 +24,20 @@ def aa_mask_weak(clip: vs.VideoNode) -> vs.VideoNode:
.std.Maximum().std.Convolution([1]*9)
def aa_mask_strong(clip: vs.VideoNode) -> vs.VideoNode:
mask: vs.VideoNode = kirsch(vsutil.get_y(clip)).std.Binarize(scale_thresh(0.25, clip)) \
.std.Maximum().std.Convolution([1]*9)
def mask_strong(clip: vs.VideoNode) -> vs.VideoNode:
mask: vs.VideoNode = SMDegrain(vsutil.get_y(clip), tr=3, thSAD=500, RefineMotion=True, prefilter=4) \
.std.Prewitt().std.Binarize(scale_thresh(0.25, clip)).std.Maximum().std.Convolution([1]*9)
return mask
def aa_mask(clip: vs.VideoNode, weak: Union[Range, List[Range], None] = None) -> vs.VideoNode:
weak = weak or []
return replace_ranges(aa_mask_strong(clip), aa_mask_weak(clip), weak)
def combine_mask(clip: vs.VideoNode, weak: Union[Range, List[Range], None] = None) -> vs.VideoNode:
return replace_ranges(mask_strong(clip), mask_weak(clip), weak or [])
def sraa_clamp(clip: vs.VideoNode, mask: Optional[vs.VideoNode] = None,
strength: float = 3, opencl: bool = False) -> vs.VideoNode:
sraa = upscaled_sraa(clip, rfactor=1.3, opencl=opencl,
downscaler=lambda c, w, h: c.resize.Bicubic(w, h, filter_param_a=0, filter_param_b=1/2))
strength: float = 2, opencl: bool = False,
postprocess: Optional[Callable[[vs.VideoNode], vs.VideoNode]] = None) -> vs.VideoNode:
sraa = upscaled_sraa(clip, rfactor=1.3, opencl=opencl, downscaler=Bicubic(b=0, c=1/2).scale)
sraa = postprocess(sraa) if postprocess else sraa
clamp = clamp_aa(clip, nnedi3(clip, opencl=opencl), sraa, strength=strength)
return core.std.MaskedMerge(clip, clamp, mask, planes=0) if mask else clamp