Tovershoot,Sovershoot,是clamp的tolerance,用于在Spatial上限制锐化。默认是0(no tolerance)。Tlimit和Slimit对应开启或者关闭temporal和Spatial limit。TodyYDDY 写了:貌似limit,Tlimit,Slimit,Tovershoot,Sovershoot等限制参数对结果没什么影响?
算法弱,看脚本只能了解大致处理过程
代码: 全选
def mwenhance(diffClip, chroma=False, Strength=2.0, Szrp8=8, Spwr=4, SdmpLo=4, SdmpHi=48, Soft=0):
# constant values for sharpening LUT
sbitPS = diffClip.format.bits_per_sample
bpsMul8 = 1 << (sbitPS - 8)
floor = 0
ceil = (1 << sbitPS) - 1
neutral = 1 << (sbitPS - 1)
neutralstr = ' {} '.format(neutral)
miSpwr = 1 / Spwr
Szrp = Szrp8 * bpsMul8
Szrp8Sqr = Szrp8 * Szrp8
SzrpMulStrength = Szrp * Strength
Szrp8SqrPlusSdmpLo = Szrp8Sqr + SdmpLo
SdmpHiEqual0 = SdmpHi == 0
Szrp8DivSdmpHiPower4Plus1 = 1 if SdmpHiEqual0 else (Szrp8 / SdmpHi) ** 4 + 1
# function to generate sharpening LUT
def diffEhFunc(x):
if x == neutral:
return x
diff = x - neutral
absDiff = abs(diff)
diff8 = diff / bpsMul8
absDiff8 = abs(diff8)
diff8Sqr = diff8 * diff8
signMul = 1 if diff >= 0 else -1
res1 = (absDiff / Szrp) ** miSpwr * SzrpMulStrength * signMul
res2 = diff8Sqr * Szrp8SqrPlusSdmpLo / ((diff8Sqr + SdmpLo) * Szrp8Sqr)
res3 = 0 if SdmpHiEqual0 else (absDiff8 / SdmpHi) ** 4
enhanced = res1 * res2 * Szrp8DivSdmpHiPower4Plus1 / (1 + res3)
return min(ceil, max(floor, round(neutral + enhanced)))
# apply sharpening LUT and soften the result
if Strength > 0:
diffClip = core.std.Lut(diffClip, [0,1,2] if chroma else [0], function=diffEhFunc)
if Soft > 0:
diffClipEhSoft = core.rgvs.RemoveGrain(diffClip, [19, 19 if chroma else 0])
diffClipEhSoft = diffClipEhSoft if Soft >= 1 else core.std.Merge(diffClip, diffClipEhSoft, [1 - Soft, Soft])
limitDiffExpr = 'x ' + neutralstr + ' - abs y ' + neutralstr + ' - abs <= x y ?'
diffClip = core.std.Expr([diffClip, diffClipEhSoft], [limitDiffExpr, limitDiffExpr if chroma else ''])
# output
return diffClip
mawen1250 写了:我没仔细看haf.LSFmod那个表达式,不知道那个x + ...是否正确,我自己的实现里是neutral + ...
贴一个我脚本里用的,注意这里Strength的1.0等于LSFmod/CSmod的100,而且附带了Soft:代码: 全选
def mwenhance(diffClip, chroma=False, Strength=2.0, Szrp8=8, Spwr=4, SdmpLo=4, SdmpHi=48, Soft=0): # constant values for sharpening LUT sbitPS = diffClip.format.bits_per_sample bpsMul8 = 1 << (sbitPS - 8) floor = 0 ceil = (1 << sbitPS) - 1 neutral = 1 << (sbitPS - 1) neutralstr = ' {} '.format(neutral) miSpwr = 1 / Spwr Szrp = Szrp8 * bpsMul8 Szrp8Sqr = Szrp8 * Szrp8 SzrpMulStrength = Szrp * Strength Szrp8SqrPlusSdmpLo = Szrp8Sqr + SdmpLo SdmpHiEqual0 = SdmpHi == 0 Szrp8DivSdmpHiPower4Plus1 = 1 if SdmpHiEqual0 else (Szrp8 / SdmpHi) ** 4 + 1 # function to generate sharpening LUT def diffEhFunc(x): if x == neutral: return x diff = x - neutral absDiff = abs(diff) diff8 = diff / bpsMul8 absDiff8 = abs(diff8) diff8Sqr = diff8 * diff8 signMul = 1 if diff >= 0 else -1 res1 = (absDiff / Szrp) ** miSpwr * SzrpMulStrength * signMul res2 = diff8Sqr * Szrp8SqrPlusSdmpLo / ((diff8Sqr + SdmpLo) * Szrp8Sqr) res3 = 0 if SdmpHiEqual0 else (absDiff8 / SdmpHi) ** 4 enhanced = res1 * res2 * Szrp8DivSdmpHiPower4Plus1 / (1 + res3) return min(ceil, max(floor, round(neutral + enhanced))) # apply sharpening LUT and soften the result if Strength > 0: diffClip = core.std.Lut(diffClip, [0,1,2] if chroma else [0], function=diffEhFunc) if Soft > 0: diffClipEhSoft = core.rgvs.RemoveGrain(diffClip, [19, 19 if chroma else 0]) diffClipEhSoft = diffClipEhSoft if Soft >= 1 else core.std.Merge(diffClip, diffClipEhSoft, [1 - Soft, Soft]) limitDiffExpr = 'x ' + neutralstr + ' - abs y ' + neutralstr + ' - abs <= x y ?' diffClip = core.std.Expr([diffClip, diffClipEhSoft], [limitDiffExpr, limitDiffExpr if chroma else '']) # output return diffClip
求教大大Evalyn 写了:clip = nnrs.nnedi3_resample(clip, width * ss_w, height * ss_h, nnrs=3)