版面规则
提问时请注意:尽量详细描述操作过程、AVS脚本内容等,最好能写出片名,只贴图有时无法看出问题原因。
提示:发布原创内容请尽量使用附件上传。使用网盘会出现过期失效的问题,请注意。
头像
zhongpang
帖子: 93
注册时间: 2011-10-23 20:45

Re: 【教程】 MaskTools入門教程

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
头像
06_taro
核心会员
核心会员
帖子: 998
注册时间: 2010-09-22 18:32
来自: United Kingdom
联系: 网站

Re: 【教程】 MaskTools入門教程

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)。
つまんねー事聞くなよ!

I, personally, for me, believe (obviously sometimes) that my OS choice is right. That's me. I'm not telling you that you should believe it. Learn the facts, and the origins behind the facts, and make up your own damn mind. That's why you have one. (source)

Follow me: @06_taro

304——
为纪念伟大的宇宙史上最强压制304先生,联合国教科文组织决定,将每年的第304天,即平年的10月31日或者闰年的10月30日,定为世界304日。
头像
yabbay
帖子: 62
注册时间: 2012-05-31 10:39
来自: Tokyo

Re: 【教程】 MaskTools入門教程

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))}
          .∧__,,∧
         ( ´・ω・`) ブルブル
          (つまくら) アリと明日(ant and tomorrow)
          `u―u´ レッツ・エッグ・ペイン(Let`s egg pain)
头像
mawen1250
核心会员
核心会员
帖子: 670
注册时间: 2011-07-24 20:33

Re: 【教程】 MaskTools入門教程

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)
头像
06_taro
核心会员
核心会员
帖子: 998
注册时间: 2010-09-22 18:32
来自: United Kingdom
联系: 网站

Re: 【教程】 MaskTools入門教程

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

I, personally, for me, believe (obviously sometimes) that my OS choice is right. That's me. I'm not telling you that you should believe it. Learn the facts, and the origins behind the facts, and make up your own damn mind. That's why you have one. (source)

Follow me: @06_taro

304——
为纪念伟大的宇宙史上最强压制304先生,联合国教科文组织决定,将每年的第304天,即平年的10月31日或者闰年的10月30日,定为世界304日。
头像
yabbay
帖子: 62
注册时间: 2012-05-31 10:39
来自: Tokyo

Re: 【教程】 MaskTools入門教程

06_taro大,mawen1250大 gracias
学到不少 {:cat_11}
          .∧__,,∧
         ( ´・ω・`) ブルブル
          (つまくら) アリと明日(ant and tomorrow)
          `u―u´ レッツ・エッグ・ペイン(Let`s egg pain)
头像
zhongpang
帖子: 93
注册时间: 2011-10-23 20:45

Re: 【教程】 MaskTools入門教程

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分布局部加噪了
头像
zhongpang
帖子: 93
注册时间: 2011-10-23 20:45

Re: 【教程】 MaskTools入門教程

请问,有没有方法让mt_edge侦测出的封闭区域都变成(255,0,0)呢?
头像
cpu100
帖子: 28
注册时间: 2010-11-09 14:43

Re: 【教程】 MaskTools入門教程

造福的行为,必须支持,也希望更多的大虾能多多的分享些更多的教程以及分享个人的经验。
有的时候自己摸索的确走了不少的路,,,,谢谢!
头像
ccsdken
帖子: 3
注册时间: 2012-07-09 23:17

Re: 【教程】 MaskTools入門教程

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

回到 “AviSynth”