salty1
帖子: 12
注册时间: 2010-10-17 21:05

Re: Contra-Sharpen mod —— EP锐化/还原用脚本,VS移植版

和楼上一样的错,limit打开,同时指定了filtered和source时,锐化强度超过了source
TodyYDDY
帖子: 14
注册时间: 2015-12-15 23:13

Re: Contra-Sharpen mod —— EP锐化/还原用脚本,VS移植版

把clamp从AVS版抄过来后(不知道错了没有),Tlimit和Slimit能发挥作用,但是limit似乎仍不起作用。

def clamp(clip, Bclip, Dclip, overshoot=0, undershoot=0, planes=[0,1,2]):
os16 = overshoot*256
us16 = undershoot*256
brightdiff = core.std.MakeDiff(clip, Bclip, [0,1,2] if chroma else [0])
darkdiff = core.std.MakeDiff(clip, Dclip, [0,1,2] if chroma else [0])
brightDdec = core.std.Expr(brightdiff, "x "+str(os16)+" - 32768 > x "+str(os16)+" - 32768 ?", [0,1,2] if chroma else [0])
darkDdec = core.std.Expr(darkdiff , "x "+str(us16)+" + 32768 < x "+str(us16)+" + 32768 ?", [0,1,2] if chroma else [0])
return core.std.Expr([clip,brightDdec,darkDdec], "x y - z - 65536 +", [0,1,2] if chroma else [0])
TodyYDDY
帖子: 14
注册时间: 2015-12-15 23:13

Re: Contra-Sharpen mod —— EP锐化/还原用脚本,VS移植版

今天发现两个疑似有问题的地方:

1. Soothe那段应该像Soft一样用SootheMP = multiple * Soothe 代替Soothe吧?

2. Smode等于3的时候, return中第一个x似乎是neutral?

return min(max(round(neutral + (abs(tmp1) / Szrp) ** (1 / Spwr) * Szrp * (strength / 100 *

multiple) * (1 if x > neutral else -1) * (tmp2 * (tmp3 + SdmpLo) / ((tmp2 + SdmpLo) * tmp3)) * ((1 + (0 if SdmpHi == 0 else

(Szrp / SdmpHi) ** 4)) / (1 + (0 if SdmpHi == 0 else (abs(tmp1) / SdmpHi) ** 4)))), 0), peak)
头像
Evalyn
帖子: 17
注册时间: 2014-07-19 20:49

Re: Contra-Sharpen mod —— EP锐化/还原用脚本,VS移植版

TodyYDDY 写了:貌似limit,Tlimit,Slimit,Tovershoot,Sovershoot等限制参数对结果没什么影响?
算法弱,看脚本只能了解大致处理过程 {:cat_5}
Tovershoot,Sovershoot,是clamp的tolerance,用于在Spatial上限制锐化。默认是0(no tolerance)。Tlimit和Slimit对应开启或者关闭temporal和Spatial limit。
至于limit参数,是控制是否依据source clip对filtered clip做Repair(3x3邻域像素限制),只在(Defined(source) || Defined(filter_ss) || usepasf) == true时有效。

最近也有人反应锐化后的ringing较重。我怀疑可能是non-ring Splineresize那块写出bug了。从avs移植了雯姐的自适应的non-ring splineresize,但自适应的spline插值计算那块可能有问题,但近期真的是好忙。。我有时间会抽空再debug看看。

至于你后面反应的。Soothe是一个百分比。用于保留多少锐化结果。所以是0-100的 scale。没必要multiple,
还有Smode 3的那个Lut,原本就比较复杂。。当时雯姐直接推荐我看Holy姐写好的LSFmod了,于是那块我也是照抄过来的。下面我也有附上逆波兰原表达式。应该没错。(有空我会一并检查下。。
► 显示剧情透露 欢迎各路姐姐前来照顾萝莉
头像
mawen1250
核心会员
核心会员
帖子: 670
注册时间: 2011-07-24 20:33

Re: Contra-Sharpen mod —— EP锐化/还原用脚本,VS移植版

我没仔细看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
TodyYDDY
帖子: 14
注册时间: 2015-12-15 23:13

Re: Contra-Sharpen mod —— EP锐化/还原用脚本,VS移植版

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


我对这个Smode是这样理解的(按AVS版的写法):

sharpdiff = neutral +/- F*S*RL*RH

”高低diff分界“zeropoint
“非线性系数”F=(absDiff/zeropoint)^(1/power),作用随power增大而增强
”基准锐化强度“S=zeropoint*strength/100
“低diff折减系数“RL=RL(damp_Low,zeropoint,absDiff)
“高diff折减系数“HL=HL(damp_High,zeropoint,absDiff)



如果上述理解正确的话,请问第二项是否等效于S=strength?

另外顺便请教一下写vpy时有什么办法可以方便查看YUV值?(如果想调节zeropoint的话会方便不少吧......)
lwjkk666
帖子: 321
注册时间: 2012-05-29 13:43

Re: Contra-Sharpen mod —— EP锐化/还原用脚本(v0.2.5解决ringing问题)

要怎样设置才是P16输出已解决
NAVras
帖子: 141
注册时间: 2016-04-24 1:32

Re: Contra-Sharpen mod —— EP锐化/还原用脚本(v0.2.5解决ringing问题)

有doc之类的嘛?
想实现像avs版一样根据源修复且强度超过源,但貌似cs=clip1.csmod(clip2,……)这样不对

参数说明在原版avsi里
然后是ret=cs.CSMOD(filtered, source=...)
上次由 NAVras 在 2016-07-13 21:27,总共编辑 3 次。
NAVras
帖子: 141
注册时间: 2016-04-24 1:32

Re: Contra-Sharpen mod —— EP锐化/还原用脚本(v0.2.5解决ringing问题)

Evalyn 写了:clip = nnrs.nnedi3_resample(clip, width * ss_w, height * ss_h, nnrs=3)
求教大大 {:cat_3}
按这个写时报错没有nnrs,看wawen了大大写在avsi里的,“nnrs”是不是要改成“nns”?

回到 “VapourSynth”