Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### ONLY FOR PROGRESSIVE VIDEO or Field Based
- ### Based on Didée's script
- ### 2019.07.22 mod
- Function DDComb(clip c, float "band", bool "static", bool "strong", bool "checkmate")
- {
- avs26 = !(VersionNumber() < 2.60)
- band = default(band,0)
- static = default(static,false)
- strong = default(strong,false)
- usecheck = default(checkmate,!strong)
- sisField = c.IsFieldBased()
- c
- borders = sisField ? weave().bicubicresize(width()/2,height()/2).separatefields().bicubicresize(width()+8,height()) : bicubicresize(width()/2,height()/2).bicubicresize(width()+8,height())
- stackhorizontal(borders.crop(0,0,4,0),last,borders.crop(width()+4,0,0,0))
- o=last ox=o.width() oy=o.height()
- clean1 = sisField ? strong ? avs26 ? o.aBlur(2, blurv=0).Repair(o.vinverse2H(uv=1, pass=strong ? 5 : 1),9,-1) : o.blur(1,0).Vinverse2H(uv=1, pass=strong ? 6 : 1) : o.vinverse2H(uv=1) : o.separatefields().vinverse2(uv=1).weave()
- D1 = mt_makediff(o,clean1)
- D8 = avs26 ? YToUV(D1.utoy8(),D1.vtoy8(),D1.converttoy8().bicubicresize(ox/2-72,oy).blur(1,0).bicubicresize(ox,oy,1,0)) : D1.bicubicresize(ox/2-72,oy).blur(1,0).bicubicresize(ox,oy,1,0)
- D9 = mt_lutxy(D1,D8,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?")
- clean1a = clean1.mt_adddiff(D9,U=2,V=2)
- clean1b = strong && avs26 && sisField ? sBlackerPixel(o=clean1a,filtered=clean1a.aBlur(1, blurv=0).Repair(clean1a,9,-1),mdifffade=128,averagewithwhiterPixel=true) : clean1a.frfun7(1.01,8,0)
- clean1b = sisField && !(clean1b.IsFieldBased()) ? c.getparity() ? clean1b.AssumeBFF().AssumeFieldBased().AssumeTFF() : clean1b.AssumeTFF().AssumeFieldBased().AssumeBFF() : clean1b
- allD = mt_makediff(o,clean1b)
- shrpD = mt_makediff(clean1b,clean1b.removegrain(20,-1))
- DD = shrpD.repair(allD,13,-1).mt_lutxy(shrpD,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?")
- clean1b = strong ? sBlackerPixel(o=clean1b, filtered=sisField && avs26 ? clean1a.aBlur(1, blurv=0).Repair(clean1a,9,-1) : clean1a.Blur(1,0).Blur(1,sisField ? 0 : 1),averagewithwhiterPixel=avs26,averagewithwhiterPixelrep=2,deeponly=!usecheck) : clean1b
- clean1c = clean1b.mt_lutxy(clean1a,"x 3 + y < x 2 + x y < x 1 + x 3 - y > x 2 - x y > x 1 - x ? ? ? ?",U=2,V=2)
- \.mt_adddiff(sisField ? DD.sbrH(strong ? 3 : 1) : DD.sbr())
- clean1c = clean1c.crop(4,0,-4,0,true)
- dirty2c = static ? sisField ? c.weave() : c : nop()
- clean2a = static ? dirty2c.tcomb(mode=0) : nop()
- clean2b = static && usecheck ? clean2a.checkmate(tthr2=0) : clean2a
- clean2b = static ? sisField ? clean2b.separatefields() : clean2b : nop()
- clean2b = static ? sisField ? clean2b.Repair(clean1c,9,-1) : clean2b : nop()
- clean2m = static ? mt_lutxy(c,clean2b,"x y == 0 x 64 <= x y - abs 32 < 255 x y - abs 48 < 255 255 48 / x y - abs * - 0 ? ? y 40 > x y > & x y - 16 >= 255 x y - 16 < ? 255 16 / x y - * 0 ? 0 ? ? ?").mt_inflate(155,155) : nop()
- clean3c = static ? mt_merge(clean1c,clean2b,clean2m,U=1,V=1) : clean1c
- clean3c = clean3c.mergechroma(c)
- output = band != 0 ? clean3c.gradfun3(thr=band,smode=2) : clean3c
- return output
- #--- end of script ---#
- }
- #######################################################
- #--- Helper functions below ---#
- function Vinverse2(clip clp, float "sstr", int "amnt", int "uv")
- {
- uv = default(uv,3)
- sstr = default(sstr,2.7)
- amnt = default(amnt,255)
- uv2 = (uv==2) ? 1 : uv
- STR = string(sstr)
- AMN = string(amnt)
- vblur = clp.sbrV()
- vblurD = mt_MakeDiff(clp,vblur,U=uv2,V=uv2)
- Vshrp = mt_LutXY(vblur,vblur.mt_convolution("1","1 2 1"),expr="x x y - "+STR+" * +",U=uv2,V=uv2)
- VshrpD = mt_MakeDiff(Vshrp,vblur,U=uv2,V=uv2)
- VlimD = mt_LutXY(VshrpD,VblurD,expr="x 128 - y 128 - * 0 < x 128 - abs y 128 - abs < x y ? 128 - 0.25 * 128 + x 128 - abs y 128 - abs < x y ? ?",U=uv2,V=uv2)
- mt_AddDiff(Vblur,VlimD,U=uv,V=uv)
- (amnt>254) ? last : (amnt==0) ? clp : mt_LutXY(clp,last,expr="x "+AMN+" + y < x "+AMN+" + x "+AMN+" - y > x "+AMN+" - y ? ?",U=uv,V=uv)
- return(last)
- }
- function sbrV(clip o)
- {
- rg11=mt_convolution("1","1 2 1")
- rg11D=mt_makediff(o,rg11)
- rg11DD=mt_makediff(rg11D,rg11D.mt_convolution("1","1 2 1")).mt_lutxy(rg11D,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?")
- o.mt_makediff(rg11DD,U=2,V=2)
- }
- function Vinverse2H(clip clp, float "sstr", int "amnt", int "uv", int "pass")
- {
- uv = default(uv,3)
- sstr = default(sstr,2.7)
- amnt = default(amnt,255)
- uv2 = (uv==2) ? 1 : uv
- STR = string(sstr)
- AMN = string(amnt)
- pass = Default(pass, 1)
- Hblur = clp.sbrH(pass)
- HblurD = mt_MakeDiff(clp,Hblur,U=uv2,V=uv2)
- Hshrp = mt_LutXY(Hblur,spasses(Hblur, pass, """mt_convolution("1 2 1","1")"""),expr="x x y - "+STR+" * +",U=uv2,V=uv2)
- HshrpD = mt_MakeDiff(Hshrp,Hblur,U=uv2,V=uv2)
- HlimD = mt_LutXY(HshrpD,HblurD,expr="x 128 - y 128 - * 0 < x 128 - abs y 128 - abs < x y ? 128 - 0.25 * 128 + x 128 - abs y 128 - abs < x y ? ?",U=uv2,V=uv2)
- mt_AddDiff(Hblur,HlimD,U=uv,V=uv)
- (amnt>254) ? last : (amnt==0) ? clp : mt_LutXY(clp,last,expr="x "+AMN+" + y < x "+AMN+" + x "+AMN+" - y > x "+AMN+" - y ? ?",U=uv,V=uv)
- return(last)
- }
- function sbrH(clip o, int "pass")
- {
- pass = Default(pass, 1)
- rg11=spasses(o, pass, """mt_convolution("1 2 1","1")""")
- rg11D=mt_makediff(o,rg11)
- rg11DD=mt_makediff(rg11D,spasses(rg11D, pass, """mt_convolution("1 2 1","1")""")).mt_lutxy(rg11D,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?")
- o.mt_makediff(rg11DD,U=2,V=2)
- }
- Function spasses(clip i, int "pass", string "filter")
- {
- return pass > 0 ? eval("spasses(i." + filter + ", pass-1, filter)") : i
- }
- # sBlackerPixel by A.SONY, for repairing DeCrawled and dehaloed clip
- # v1.56
- function sBlackerPixel(clip "o", clip "filtered", float "maxdiff", float "thr", bool "linflate", float "mdifffade", clip "o2", val "averagewithwhiterPixel", int "averagewithwhiterPixelrep", bool "deeponly")
- {
- maxdiff = default(maxdiff, 32)
- thr = default(thr, 40)
- mdifffade = default(mdifffade, maxdiff*3/2.0) #should be more than the maxdiff
- linflate = default(linflate, true)
- whidorep = defined(averagewithwhiterPixelrep)
- Assert((defined(o) && defined(filtered)), "both o clip and filtered clip are needed")
- doaverage = defined(averagewithwhiterPixel)
- whiterPixelclip = doaverage ? isclip(averagewithwhiterPixel) ? averagewithwhiterPixel : isstring(averagewithwhiterPixel) ? eval(averagewithwhiterPixel) : swhiterPixel(o, filtered, maxdiff, 255-thr, linflate, mdifffade, o2, deeponly) : nop()
- dpmask = mdifffade!=0 ? VersionNumber() < 2.6 ? o.mt_lutxy(filtered,"y "+string(thr)+" > x y > & x y - "+string(maxdiff)+" < 255 x y - "+string(mdifffade)+" < ? 255 255 "+string(mdifffade)+" / x y - * - 0 ? 0 ?")
- \ : o.mt_lutxy(filtered,"y "+string(thr)+" scalef > x y > & x y - "+string(maxdiff)+" scalef < range_max x y - "+string(mdifffade)+" scalef < ? range_max range_max "+string(mdifffade)+" scalef / x y - * - 0 ? 0 ?",use_expr=2) : nop()
- mdifffade!=0 ? Mt_Merge(defined(o2) ? o2 : o,filtered, linflate ? dpmask.mt_inflate(155) : dpmask,U=2,V=2) : \
- VersionNumber() < 2.6 ? o.mt_lutxy(filtered,"x y > y "+string(thr)+" > & x y - "+string(maxdiff)+" < & y x ?",U=2,V=2)
- \ : o.mt_lutxy(filtered,"x y > y "+string(thr)+" scalef > & x y - "+string(maxdiff)+" scalef < & y x ?",use_expr=2,U=2,V=2)
- doaverage ? whidorep ? mt_average(last, whiterPixelclip.Repair(o,averagewithwhiterPixelrep,-1), u=2, v=2) : mt_average(last, whiterPixelclip, u=2, v=2) : last
- }
- # swhiterPixel by A.SONY
- # v1.26
- function swhiterPixel(clip "o", clip "filtered", float "maxdiff", float "thr", bool "linflate", float "mdifffade", clip "o2", bool "deeponly")
- {
- maxdiff = default(maxdiff, 32)
- thr = default(thr, 215)
- mdifffade = default(mdifffade, maxdiff*3/2.0) #should be more than the maxdiff
- linflate = default(linflate, true)
- deeponly = default(deeponly, false)
- Assert((defined(o) && defined(filtered)), "both o clip and filtered clip are needed")
- wpmask = mdifffade!=0 ? VersionNumber() < 2.6 ? o.mt_lutxy(filtered,"y "+string(thr)+" < x y < & y x - "+string(maxdiff)+" > 255 y x - "+string(mdifffade)+" > ? 255 255 "+string(mdifffade)+" / y x - * - 0 ? 0 ?")
- \ : o.mt_lutxy(filtered,"y "+string(thr)+" scalef < x y < & y x - "+string(maxdiff)+" scalef > range_max y x - "+string(mdifffade)+" scalef > ? range_max range_max "+string(mdifffade)+" scalef / y x - * - 0 ? 0 ?",use_expr=2) : nop()
- wpmask = mdifffade!=0 && deeponly ? wpmask.mt_invert().mt_expand(155).mt_inpand(155).mt_invert() : wpmask
- mdifffade!=0 ? Mt_Merge(defined(o2) ? o2 : o,filtered, linflate ? wpmask.mt_inflate(155) : wpmask,U=2,V=2) : \
- VersionNumber() < 2.6 ? o.mt_lutxy(filtered,"x y < y "+string(thr)+" < & y x - "+string(maxdiff)+" > & y x ?",U=2,V=2)
- \ : o.mt_lutxy(filtered,"x y < y "+string(thr)+" scalef < & y x - "+string(maxdiff)+" scalef > & y x ?",use_expr=2,U=2,V=2)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement