Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import log2
- def unsharp(clip, radius=1, strength=log2(3), custom=None):
- if callable(custom):
- return clip.std.MergeDiff(clip.std.MakeDiff(custom(clip)))
- strength = max(1e-6, min(strength, log2(3)))
- weight = 0.5 ** strength / ((1 - 0.5 ** strength) / 2)
- # find matrix with least rounding error when using integer clips
- if clip.format.sample_type == 0:
- all_matrices = [[x] for x in range(1, 1024)]
- for x in range(1023):
- while len(all_matrices[x]) < radius * 2 + 1:
- all_matrices[x].append(all_matrices[x][-1] / weight)
- error = [sum([abs(x - round(x)) for x in matrix[1:]]) for matrix in all_matrices]
- matrix = [round(x) for x in all_matrices[error.index(min(error))]]
- else:
- matrix = [1]
- while len(matrix) < radius * 2 + 1:
- matrix.append(matrix[-1] / weight)
- matrix = [matrix[x] for x in [(2,1,2,1,0,1,2,1,2), (4,3,2,3,4,3,2,1,2,3,2,1,0,1,2,3,2,1,2,3,4,3,2,3,4)][radius-1]]
- return clip.std.MergeDiff(clip.std.MakeDiff(clip.std.Convolution(matrix)))
- y = depth(get_y(clip), 16)
- y0=y
- clips = [y, y.znedi3.nnedi3(1), y.znedi3.nnedi3(0)]
- s = unsharp(y, radius=1, strength=log2(3))
- out = core.std.Expr([s]+clips, 'x y z a max max min y z a min min max')
- y = out.std.Transpose()
- clips = [y, y.znedi3.nnedi3(1), y.znedi3.nnedi3(0)]
- s = unsharp(y, radius=1, strength=log2(3))
- out = core.std.Expr([s]+clips, 'x y z a max max min y z a min min max').std.Transpose()
- core.std.Interleave(y0, out).set_output()
- """ dunno what went wrong here but dont wanna delete it
- import math
- def unsharp(clip, radius=1, strength=math.log2(3), custom=None):
- if callable(custom):
- return clip.std.MergeDiff(clip.std.MakeDiff(custom(clip)))
- strength = max(1e-6, min(strength, math.log2(3)))
- weight = 0.5 ** strength / ((1 - 0.5 ** strength) / 2)
- # find matrix with least rounding error when using integer clips
- if clip.format.sample_type == 0:
- all_matrices = [[x] for x in range(1, 1024)]
- for x in range(1023):
- while len(all_matrices[x]) < radius * 2 + 1:
- all_matrices[x].append(all_matrices[x][-1] / weight)
- error = [sum([abs(x - round(x)) for x in matrix[1:]]) for matrix in all_matrices]
- matrix = [round(x) for x in all_matrices[error.index(min(error))]]
- else:
- matrix = [1]
- while len(matrix) < radius * 2 + 1:
- matrix.append(matrix[-1] / weight)
- matrix = [matrix[x] for x in [(2,1,2,1,0,1,2,1,2), (4,3,2,3,4,3,2,1,2,3,2,1,0,1,2,3,2,1,2,3,4,3,2,3,4)][radius-1]]
- return clip.std.MergeDiff(clip.std.MakeDiff(clip.std.Convolution(matrix)))
- def pre_aa(clip, radius=1, strength=math.log2(3), pp=None, **nnedi3_params):
- sharp = unsharp(clip, radius=radius, strength=strength)
- nedi = clip.znedi3.nnedi3(3, **nnedi3_params).std.SeparateFields(True).std.SelectEvery(4, [0, 3]).std.DoubleWeave()[::2]
- if callable(pp):
- nedi = pp(nedi)
- clip = core.std.Expr([sharp, clip, nedi], 'x y z max min y z min max').std.Transpose()
- sharp = unsharp(clip, radius=radius, strength=strength)
- nedi = clip.znedi3.nnedi3(3, **nnedi3_params).std.SeparateFields(True).std.SelectEvery(4, [0, 3]).std.DoubleWeave()[::2]
- if callable(pp):
- nedi = pp(nedi)
- return core.std.Expr([sharp, clip, nedi], 'x y z max min y z min max').std.Transpose()
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement