分页: 5 / 6

Re: 【教程】 MaskTools入門教程

发表于 : 2012-06-25 13:06
zhongpang
yabbay 写了:刚开始读第二遍 又有一个小白问题
当原文中
mt_merge(dfttest,g_mask,luma=true)
这样调用merge的时候貌似只写了2个clip,
函数怎么自动判断哪个是clip a 哪个是clip b 哪个是clip mask? {:cat_13}
last是clip a,dfttest是clip b

Re: 【教程】 MaskTools入門教程

发表于 : 2012-06-25 13:54
06_taro
zhongpang 写了: 感谢指点,请问有没有在16bit下做差的工具呢?
目前只有对msb和lsb分别做差再相加
早就寫好了,放在NRDB裡的,NRDB沒放出來結果這個也一直懶得貼出來:
[syntax lang="avisynth" lines="f" filename="makediff16.avsi"]FUNCTION makediff16(clip a, clip b, int "Y", int "U", int "V", bool "safe"){
Y = Default(Y, 3)
U = Default(U, 1)
V = Default(V, 1)

Y31 = Y == 3 ? 3 : 1
U31 = U == 3 ? 3 : 1
V31 = V == 3 ? 3 : 1

/* the expression for [makediff16(x, y)] is:
* x - y + 32768 = x + (65536 - y) - 32768,
* and it can be transferred to [adddiff16(x, lut16(y, "65536-y"))]
*/
addend = b.Dither_lut16("65536 x -", Y=Y31, U=U31, V=V31)
wrap = b.Dither_lut16("x 0 == 1 0 ?", Y=Y31, U=U31, V=V31)

diff = Dither_add16(a, addend, Y=Y31, U=U31, V=V31, dif=true)

/* only needed for pixels with value==0 (65536-0>65535),
* which should not appear in strict TV level clips,
* so it is usually safe enough to skip this wrapping.
*/
diff = Default(safe, false) ? diff.Dither_add16(wrap, Y=Y31, U=U31, V=V31, dif=false)
\ : diff

/* copy plane or not
*/
diff = ( Y==2 || U==2 || V==2 ) ? mt_lutxy( diff, a, Y=(Y==2?4:2), U=(U==2?4:2), V=(V==2?4:2) ) : diff
diff = ( Y==4 || U==4 || V==4 ) ? mt_lutxy( diff, b, Y=(Y==4?4:2), U=(U==4?4:2), V=(V==4?4:2) ) : diff

/* set plane value or not
*/
return ( Y<=0 || U<=0 || V<=0 ) ? diff.Dither_lut16( Y=(Y<=0?Y:2), U=(U<=0?U:2), V=(V<=0?V:2) )
\ : diff
}[/syntax]

yabbay 写了:刚开始读第二遍 又有一个小白问题
当原文中
mt_merge(dfttest,g_mask,luma=true)
这样调用merge的时候貌似只写了2个clip,
函数怎么自动判断哪个是clip a 哪个是clip b 哪个是clip mask? {:cat_13}
這是avs最基本的語法問題,不屬於masktools的範疇了。任何第一個參數為clip型變量的濾鏡,第一個clip變量是可以省略的,用last代替,所以上面這個相當於mt_merge(last, dfttest, g_mask, luma=true)。

Re: 【教程】 MaskTools入門教程

发表于 : 2012-06-25 15:35
yabbay
function DeHalo_alpha(clip clp, float "rx", float "ry", float "darkstr", float "brightstr", float "lowsens", float "highsens", float "ss")
{
rx = default( rx, 2.0 )
ry = default( ry, 2.0 )
darkstr = default( darkstr, 1.0 )
brightstr = default( brightstr, 1.0 )
lowsens = default( lowsens, 50 )
highsens = default( highsens, 50 )
ss = default( ss, 1.5 )

LOS = string(lowsens)
HIS = string(highsens/100.0)
DRK = string(darkstr)
BRT = string(brightstr)
ox = clp.width()
oy = clp.height()
uv = 1
uv2 = (uv==3) ? 3 : 2

halos = clp.bicubicresize(m4(ox/rx),m4(oy/ry)).bicubicresize(ox,oy,1,0)
are = mt_lutxy(clp.mt_expand(U=uv,V=uv),clp.mt_inpand(U=uv,V=uv),"x y -","x y -","x y -",U=uv,V=uv)
ugly = mt_lutxy(halos.mt_expand(U=uv,V=uv),halos.mt_inpand(U=uv,V=uv),"x y -","x y -","x y -",U=uv,V=uv)
so = mt_lutxy( ugly, are, "y x - y 0.001 + / 255 * "+LOS+" - y 256 + 512 / "+HIS+" + *" )
lets = mt_merge(halos,clp,so,U=uv,V=uv)
remove = (ss==1.0) ? clp.repair(lets,1,0)
\ : clp.lanczosresize(m4(ox*ss),m4(oy*ss))
\ .mt_logic(lets.mt_expand(U=uv,V=uv).bicubicresize(m4(ox*ss),m4(oy*ss)),"min",U=uv2,V=uv2)
\ .mt_logic(lets.mt_inpand(U=uv,V=uv).bicubicresize(m4(ox*ss),m4(oy*ss)),"max",U=uv2,V=uv2)
\ .lanczosresize(ox,oy)
them = mt_lutxy(clp,remove,"x y < x x y - "+DRK+" * - x x y - "+BRT+" * - ?",U=2,V=2)

return( them )
}

function m4(float x) {return(x<16?16:int(round(x/4.0)*4))}
举例来说如果偶想将上面这个dehalo_alpha的脚本改成luma自适应mask的dehalo的话(暗处弱dehalo 明处强dehalo) 是不是可以这样改
function DeHalo_alpha(clip clp, float "rx", float "ry", float "darkstr", float "brightstr", float "lowsens", float "highsens", float "ss")
{
rx = default( rx, 2.0 )
ry = default( ry, 2.0 )
darkstr = default( darkstr, 1.0 )
brightstr = default( brightstr, 1.0 )
lowsens = default( lowsens, 50 )
highsens = default( highsens, 50 )
ss = default( ss, 1.5 )

LOS = string(lowsens)
HIS = string(highsens/100.0)
DRK = string(darkstr)
BRT = string(brightstr)
ox = clp.width()
oy = clp.height()
uv = 1
uv2 = (uv==3) ? 3 : 2

halos = clp.bicubicresize(m4(ox/rx),m4(oy/ry)).bicubicresize(ox,oy,1,0)
are = mt_lutxy(clp.mt_expand(U=uv,V=uv),clp.mt_inpand(U=uv,V=uv),"x y -","x y -","x y -",U=uv,V=uv)
ugly = mt_lutxy(halos.mt_expand(U=uv,V=uv),halos.mt_inpand(U=uv,V=uv),"x y -","x y -","x y -",U=uv,V=uv)
so = mt_lutxy( ugly, are, "y x - y 0.001 + / 255 * "+LOS+" - y 256 + 512 / "+HIS+" + *" )
lets = mt_merge(halos,clp,so,U=uv,V=uv)
remove = (ss==1.0) ? clp.repair(lets,1,0)
\ : clp.lanczosresize(m4(ox*ss),m4(oy*ss))
\ .mt_logic(lets.mt_expand(U=uv,V=uv).bicubicresize(m4(ox*ss),m4(oy*ss)),"min",U=uv2,V=uv2)
\ .mt_logic(lets.mt_inpand(U=uv,V=uv).bicubicresize(m4(ox*ss),m4(oy*ss)),"max",U=uv2,V=uv2)
\ .lanczosresize(ox,oy)
them = mt_lutxy(clp,remove,"x y < x x y - "+DRK+" * - x x y - "+BRT+" * - ?",U=2,V=2)
now = mt_merge(clp,them,so,luma=true,chroma=process)
return(now)
}

function m4(float x) {return(x<16?16:int(round(x/4.0)*4))}

Re: 【教程】 MaskTools入門教程

发表于 : 2012-06-25 18:07
mawen1250
Dehalo_Alpha是用MaskTool1写的,你这个脚本是用Masktools2写的Dehalo_Alpha_mt。
至于luma自适应的问题,里面本来就有用来觉得处理亮halo还是暗halo的darkstr和brightstr供调整,再加个luma mask我觉得意义不大,更重要的还是用合理调整过的edge mask来限制其处理范围。另外可以在处理前用nnedi3之类的做super sampling,对于更精确的处理有帮助。

我做一个DVD upscale到720p的edgeclean部分的脚本,源有很重的ringing,所以强度比较大。
对比图见这里:http://keyfc.laputachen.com/bbs/showtopic-50470.aspx

代码: 全选

XXXSource

up            = last.nnedi3_rpow2(rfactor=2, qual=2)

emask       = up.tcanny(sigma=0.8, mode=1, plane=1)

edgeclean = up.YAHR().Dehalo_Alpha_mt(darkstr=1.0,brightstr=1.4,rx=2.4,ry=2.4,highsens=100,lowsens=30)

ecmask     = emask.mt_expand(mode=mt_square(2)).mt_lutxy(emask.mt_inpand(mode=mt_square(1)), "x y -").mt_lut("x 16 < x x 2 << ?")

eced        = mt_merge(up, edgeclean, ecmask, luma=true, Y=3, U=3, V=3)

eced.LSFmod(defaults="fast",Smode=3,Smethod=3,Lmode=1,strength=50,preblur="ON",secure=true,edgemode=0,soft=0,soothe=true,ss_x=1.00,ss_y=1.00,source=up)

Re: 【教程】 MaskTools入門教程

发表于 : 2012-06-25 18:29
06_taro
dehalo_alpha_mt出來之前很久就有人修改過其腳本以適應mt2,實際上以前我自己都放出過一個自己修改成mt2的版本(當時還只有把mt1修改成overlay的修改版,看著不爽於是自己改了)。這些版本都沒有改函數名。功能、參數、效果之類的完全相同的情況下僅僅因為內部修改而改變函數名是沒有任何必要的,函數就是一個黑盒子,使用者不需要知道內部是怎樣的,只要使用起來沒有區別就應該是同一個函數…而且其實這種情況下更應該保保持相同函數名,以提高舊腳本的兼容性。

Re: 【教程】 MaskTools入門教程

发表于 : 2012-06-25 18:32
yabbay
06_taro大,mawen1250大 gracias
学到不少 {:cat_11}

Re: 【教程】 MaskTools入門教程

发表于 : 2012-06-26 11:34
zhongpang
06_taro 写了:
zhongpang 写了: 感谢指点,请问有没有在16bit下做差的工具呢?
目前只有对msb和lsb分别做差再相加
早就寫好了,放在NRDB裡的,NRDB沒放出來結果這個也一直懶得貼出來:
[syntax lang="avisynth" lines="f" filename="makediff16.avsi"]FUNCTION makediff16(clip a, clip b, int "Y", int "U", int "V", bool "safe"){
Y = Default(Y, 3)
U = Default(U, 1)
V = Default(V, 1)

Y31 = Y == 3 ? 3 : 1
U31 = U == 3 ? 3 : 1
V31 = V == 3 ? 3 : 1

/* the expression for [makediff16(x, y)] is:
* x - y + 32768 = x + (65536 - y) - 32768,
* and it can be transferred to [adddiff16(x, lut16(y, "65536-y"))]
*/
addend = b.Dither_lut16("65536 x -", Y=Y31, U=U31, V=V31)
wrap = b.Dither_lut16("x 0 == 1 0 ?", Y=Y31, U=U31, V=V31)

diff = Dither_add16(a, addend, Y=Y31, U=U31, V=V31, dif=true)

/* only needed for pixels with value==0 (65536-0>65535),
* which should not appear in strict TV level clips,
* so it is usually safe enough to skip this wrapping.
*/
diff = Default(safe, false) ? diff.Dither_add16(wrap, Y=Y31, U=U31, V=V31, dif=false)
\ : diff

/* copy plane or not
*/
diff = ( Y==2 || U==2 || V==2 ) ? mt_lutxy( diff, a, Y=(Y==2?4:2), U=(U==2?4:2), V=(V==2?4:2) ) : diff
diff = ( Y==4 || U==4 || V==4 ) ? mt_lutxy( diff, b, Y=(Y==4?4:2), U=(U==4?4:2), V=(V==4?4:2) ) : diff

/* set plane value or not
*/
return ( Y<=0 || U<=0 || V<=0 ) ? diff.Dither_lut16( Y=(Y<=0?Y:2), U=(U<=0?U:2), V=(V<=0?V:2) )
\ : diff
}[/syntax]
感谢指点,现在可以实现根据dither分布局部加噪了

Re: 【教程】 MaskTools入門教程

发表于 : 2012-06-29 18:55
zhongpang
请问,有没有方法让mt_edge侦测出的封闭区域都变成(255,0,0)呢?

Re: 【教程】 MaskTools入門教程

发表于 : 2012-07-16 9:01
cpu100
造福的行为,必须支持,也希望更多的大虾能多多的分享些更多的教程以及分享个人的经验。
有的时候自己摸索的确走了不少的路,,,,谢谢!

Re: 【教程】 MaskTools入門教程

发表于 : 2013-02-13 23:44
ccsdken
弱弱的问一句,要怎么样做一个盖住某类视频马赛克部分的mask(咳咳)?
堆了一堆滤镜之后都糊掉了...
请菊苣们给一个思路...