Last active
January 1, 2023 19:32
-
-
Save 4re/2545a281e3f17ba6ef82 to your computer and use it in GitHub Desktop.
Revisions
-
4re revised this gist
Nov 3, 2020 . 1 changed file with 18 additions and 17 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ from vapoursynth import core, GRAY __version__ = "1.1.1" def _clamp(minimum, value, maximum): @@ -11,8 +11,7 @@ def _m4(value, mult=4.0): return 16 if value < 16 else int(round(value / mult) * mult) def psharpen(clip, strength=25, threshold=75, ss_x=1.0, ss_y=1.0, dest_x=None, dest_y=None): """From http://forum.doom9.org/showpost.php?p=683344&postcount=28 Sharpening function similar to LimitedSharpenFaster. @@ -26,7 +25,6 @@ def psharpen(clip, strength=25, threshold=75, ss_x=1.0, ss_y=1.0, dest_x (int): Output resolution after sharpening. dest_y (int): Output resolution after sharpening. """ src = clip @@ -44,36 +42,39 @@ def psharpen(clip, strength=25, threshold=75, ss_x=1.0, ss_y=1.0, ss_y = 1.0 if ss_x != 1.0 or ss_y != 1.0: clip = core.resize.Lanczos(clip, width=_m4(src.width * ss_x), height=_m4(src.height * ss_y)) resz = clip if src.format.num_planes != 1: clip = core.std.ShufflePlanes(clips=clip, planes=[0], colorfamily=GRAY) max_ = core.std.Maximum(clip) min_ = core.std.Minimum(clip) nmax = core.std.Expr([max_, min_], ["x y -"]) nval = core.std.Expr([clip, min_], ["x y -"]) expr0 = threshold * (1.0 - strength) / (1.0 - (1.0 - threshold) * (1.0 - strength)) epsilon = 0.000000000000001 scl = (1 << clip.format.bits_per_sample) // 256 x = f"x {scl} /" if scl != 1 else "x" y = f"y {scl} /" if scl != 1 else "y" expr = ( f"{x} {y} {epsilon} + / 2 * 1 - abs {expr0} < {strength} 1 = {x} {y} 2 / = 0 {y} 2 / ? " f"{x} {y} {epsilon} + / 2 * 1 - abs 1 {strength} - / ? {x} {y} {epsilon} + / 2 * 1 - abs 1 {threshold} - " f"* {threshold} + ? {x} {y} 2 / > 1 -1 ? * 1 + {y} * 2 / {scl} *" ) nval = core.std.Expr([nval, nmax], [expr]) clip = core.std.Expr([nval, min_], ["x y +"]) if src.format.num_planes != 1: clip = core.std.ShufflePlanes( clips=[clip, resz], planes=[0, 1, 2], colorfamily=src.format.color_family ) if ss_x != 1.0 or ss_y != 1.0 or dest_x != src.width or dest_y != src.height: clip = core.resize.Lanczos(clip, width=dest_x, height=dest_y) -
4re revised this gist
Apr 1, 2020 . 1 changed file with 31 additions and 36 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,21 +1,24 @@ import vapoursynth as vs __version__ = '1.1.0' def _clamp(minimum, value, maximum): return int(max(minimum, min(round(value), maximum))) def _m4(value, mult=4.0): return 16 if value < 16 else int(round(value / mult) * mult) def psharpen(clip, strength=25, threshold=75, ss_x=1.0, ss_y=1.0, dest_x=None, dest_y=None): """From http://forum.doom9.org/showpost.php?p=683344&postcount=28 Sharpening function similar to LimitedSharpenFaster. Args: clip (clip): Input clip. strength (int): Strength of the sharpening. threshold (int): Controls "how much" to be sharpened. ss_x (float): Supersampling factor (reduce aliasing on edges). @@ -25,62 +28,54 @@ def psharpen(clip, strength=25, threshold=75, ss_x=1.0, ss_y=1.0, """ core = vs.get_core() src = clip if dest_x is None: dest_x = src.width if dest_y is None: dest_y = src.height strength = _clamp(0, strength, 100) / 100.0 threshold = _clamp(0, threshold, 100) / 100.0 if ss_x < 1.0: ss_x = 1.0 if ss_y < 1.0: ss_y = 1.0 if ss_x != 1.0 or ss_y != 1.0: clip = core.resize.Lanczos(clip, width=_m4(src.width*ss_x), height=_m4(src.height*ss_y)) resz = clip if src.format.num_planes != 1: clip = core.std.ShufflePlanes(clips=clip, planes=[0], colorfamily=vs.GRAY) max_ = core.std.Maximum(clip) min_ = core.std.Minimum(clip) nmax = core.std.Expr([max_, min_], ['x y -']) nval = core.std.Expr([clip, min_], ['x y -']) expr0 = threshold * (1.0 - strength) / (1.0 - (1.0 - threshold) * (1.0 - strength)) epsilon = 0.000000000000001 scl = (1 << clip.format.bits_per_sample) // 256 x = f'x {scl} /' if scl != 1 else 'x' y = f'y {scl} /' if scl != 1 else 'y' expr = (f'{x} {y} {epsilon} + / 2 * 1 - abs {expr0} < {strength} 1 = {x} {y} 2 / = 0 {y} 2 / ? ' f'{x} {y} {epsilon} + / 2 * 1 - abs 1 {strength} - / ? {x} {y} {epsilon} + / 2 * 1 - abs 1 {threshold} - ' f'* {threshold} + ? {x} {y} 2 / > 1 -1 ? * 1 + {y} * 2 / {scl} *') nval = core.std.Expr([nval, nmax], [expr]) clip = core.std.Expr([nval, min_], ['x y +']) if src.format.num_planes != 1: clip = core.std.ShufflePlanes(clips=[clip, resz], planes=[0, 1, 2], colorfamily=src.format.color_family) if ss_x != 1.0 or ss_y != 1.0 or dest_x != src.width or dest_y != src.height: clip = core.resize.Lanczos(clip, width=dest_x, height=dest_y) return clip -
4re revised this gist
Oct 13, 2016 . 1 changed file with 2 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -48,10 +48,7 @@ def psharpen(clip, strength=25, threshold=75, ss_x=1.0, ss_y=1.0, ss_y = 1.0 if ss_x != 1.0 or ss_y != 1.0: clip = core.resize.Lanczos(clip, width=_m4(ox*ss_x), height=_m4(oy*ss_y)) orig = clip @@ -84,8 +81,6 @@ def psharpen(clip, strength=25, threshold=75, ss_x=1.0, ss_y=1.0, colorfamily=orig.format.color_family) if ss_x != 1.0 or ss_y != 1.0 or dest_x != ox or dest_y != oy: clip = core.resize.Lanczos(clip, width=dest_x, height=dest_y) return clip -
4re revised this gist
Sep 23, 2015 . 1 changed file with 7 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -9,8 +9,8 @@ def _m4(x, m=4.0): return 16 if x < 16 else int(round(x / m) * m) def psharpen(clip, strength=25, threshold=75, ss_x=1.0, ss_y=1.0, dest_x=None, dest_y=None): """From http://forum.doom9.org/showpost.php?p=683344&postcount=28 Sharpeing function similar to LimitedSharpenFaster. @@ -41,6 +41,7 @@ def psharpen(clip, strength=25, threshold=75, ss_x=1.0, ss_y=1.0, dest_x=None, strength = _clamp(0, strength, 100) threshold = _clamp(0, threshold, 100) if ss_x < 1.0: ss_x = 1.0 if ss_y < 1.0: @@ -49,8 +50,8 @@ def psharpen(clip, strength=25, threshold=75, ss_x=1.0, ss_y=1.0, dest_x=None, if ss_x != 1.0 or ss_y != 1.0: clip = core.fmtc.resample(clip, _m4(ox*ss_x), _m4(oy*ss_y), kernel="lanczos") if bd != clip.format.bits_per_sample: clip = core.fmtc.bitdepth(clip, bits=bd, dmode=1) orig = clip @@ -80,11 +81,11 @@ def psharpen(clip, strength=25, threshold=75, ss_x=1.0, ss_y=1.0, dest_x=None, if orig.format.num_planes != 1: clip = core.std.ShufflePlanes(clips=[val, orig], planes=[0, 1, 2], colorfamily=orig.format.color_family) if ss_x != 1.0 or ss_y != 1.0 or dest_x != ox or dest_y != oy: clip = core.fmtc.resample(clip, dest_x, dest_y, kernel="lanczos") if bd != clip.format.bits_per_sample: clip = core.fmtc.bitdepth(clip, bits=bd) return clip -
4re revised this gist
Sep 23, 2015 . 1 changed file with 17 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,11 @@ import vapoursynth as vs def _clamp(minimum, x, maximum): return int(max(minimum, min(round(x), maximum))) def _m4(x, m=4.0): return 16 if x < 16 else int(round(x / m) * m) @@ -21,8 +20,8 @@ def psharpen(clip, strength=25, threshold=75, ss_x=1.0, ss_y=1.0, dest_x=None, threshold (int): Controls "how much" to be sharpened. ss_x (float): Supersampling factor (reduce aliasing on edges). ss_y (float): Supersampling factor (reduce aliasing on edges). dest_x (int): Output resolution after sharpening. dest_y (int): Output resolution after sharpening. """ core = vs.get_core() @@ -40,19 +39,24 @@ def psharpen(clip, strength=25, threshold=75, ss_x=1.0, ss_y=1.0, dest_x=None, if dest_y is None: dest_y = oy strength = _clamp(0, strength, 100) threshold = _clamp(0, threshold, 100) if ss_x < 1.0: ss_x = 1.0 if ss_y < 1.0: ss_y = 1.0 if ss_x != 1.0 or ss_y != 1.0: clip = core.fmtc.resample(clip, _m4(ox*ss_x), _m4(oy*ss_y), kernel="lanczos") if bd != clip._format.bits_per_sample: clip = core.fmtc.bitdepth(clip, bits=bd) orig = clip if orig.format.num_planes != 1: clip = core.std.ShufflePlanes(clips=clip, planes=[0], colorfamily=vs.GRAY) val = clip max_ = core.std.Maximum(clip) @@ -76,9 +80,11 @@ def psharpen(clip, strength=25, threshold=75, ss_x=1.0, ss_y=1.0, dest_x=None, if orig.format.num_planes != 1: clip = core.std.ShufflePlanes(clips=[val, orig], planes=[0, 1, 2], colorfamily=orig._format.color_family) if ss_x != 1.0 or ss_y != 1.0 or dest_x != ox or dest_y != oy: clip = core.fmtc.resample(clip, dest_x, dest_y, kernel="lanczos") if bd != clip._format.bits_per_sample: clip = core.fmtc.bitdepth(clip, bits=bd) return clip -
4re created this gist
Sep 23, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,84 @@ import vapoursynth as vs import havsfunc as haf def clamp(minimum, x, maximum): return int(max(minimum, min(round(x), maximum))) def m4(x, m=4.0): return 16 if x < 16 else int(round(x / m) * m) def psharpen(clip, strength=25, threshold=75, ss_x=1.0, ss_y=1.0, dest_x=None, dest_y=None): """From http://forum.doom9.org/showpost.php?p=683344&postcount=28 Sharpeing function similar to LimitedSharpenFaster. Args: strength (int): Strength of the sharpening. threshold (int): Controls "how much" to be sharpened. ss_x (float): Supersampling factor (reduce aliasing on edges). ss_y (float): Supersampling factor (reduce aliasing on edges). dest_x (int): Output resolution after sharpening (avoid a resizing step). dest_y (int): Output resolution after sharpening (avoid a resizing step). """ core = vs.get_core() ox = clip.width oy = clip.height bd = clip.format.bits_per_sample max_ = 2 ** bd - 1 scl = (max_ + 1) // 256 x = 'x {} /'.format(scl) if bd != 8 else 'x' y = 'y {} /'.format(scl) if bd != 8 else 'y' if dest_x is None: dest_x = ox if dest_y is None: dest_y = oy strength = clamp(0, strength, 100) threshold = clamp(0, threshold, 100) if ss_x < 1.0: ss_x = 1.0 if ss_y < 1.0: ss_y = 1.0 if ss_x != 1.0 or ss_y != 1.0: clip = haf.Resize(clip, m4(ox*ss_x), m4(oy*ss_y), kernel="Lanczos") orig = clip if orig.format.num_planes != 1: clip = core.std.ShufflePlanes(clips=clip, planes=[0], colorfamily=vs.GRAY) val = clip max_ = core.std.Maximum(clip) min_ = core.std.Minimum(clip) nmax = core.std.Expr([max_, min_], ['x y -']) nval = core.std.Expr([val, min_], ['x y -']) s = strength/100.0 t = threshold/100.0 x0 = t * (1.0 - s) / (1.0 - (1.0 - t) * (1.0 - s)) expr = ('{x} {y} / 2 * 1 - abs {x0} < {s} 1 = {x} {y} 2 / = 0 {y} 2 / ? ' '{x} {y} / 2 * 1 - abs 1 {s} - / ? {x} {y} / 2 * 1 - abs 1 {t} - ' '* {t} + ? {x} {y} 2 / > 1 -1 ? * 1 + {y} * 2 / {scl} *').format( x=x, y=y, x0=x0, t=t, s=s, scl=scl) nval = core.std.Expr([nval, nmax], [expr]) val = core.std.Expr([nval, min_], ['x y +']) if orig.format.num_planes != 1: clip = core.std.ShufflePlanes(clips=[val, orig], planes=[0, 1, 2], colorfamily=orig.format.color_family) if ss_x != 1.0 or ss_y != 1.0 or dest_x != ox or dest_y != oy: clip = haf.Resize(clip, dest_x, dest_y, kernel="Lanczos") return clip