Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # DeHaloHmod 22 6 2016
- function GreyCenteredToMask_dhh(clip input) {
- input.Levels(128, 1, 255, 0, 255, false)
- one = last
- input.Levels(0, 1, 128, 255, 0, false)
- two = last
- Overlay(one, two, mode="lighten")
- }
- function FastLineDarkenMOD3_dhh( clip c, int "strength", int "prot", int "luma_cap", int "threshold", int "thinning")
- {
- ## parameters ##
- str = string(default(strength, 48) /128.)
- lum = string(default(luma_cap, 191))
- protection = default(prot,5)
- thr = string(default(threshold, 4))
- thinning = default(thinning,0)
- thn = string(thinning /16.)
- ## filtering ##
- exin = c.mt_expand(thy=255/(protection+1)).mt_inpand()
- diff = mt_lutxy(c,exin,yexpr="y "+lum+" < y "+lum+" ? x "+thr+" + > x y "+lum+" < y "+lum+" ? - 0 ? 127 +",uexpr="x",vexpr="x",u=2, v=2)
- linemask= mt_lut(diff.mt_inpand(),"x 127 - "+thn+" * 255 +").mt_convolution("1 1 1","1 1 1",y=3,u=0,v=0)#".RemoveGrain(20,-1)" gives a little speed boost.
- thick = mt_lutxy(c, exin, yexpr="y "+lum+" < y "+lum+" ? x "+thr+" + > x y "+lum+" < y "+lum+" ? - 0 ? "+str+" * x +",uexpr="x",vexpr="x",u=2, v=2)
- thin = mt_lutxy(c.mt_expand(U=2,V=2),diff,yexpr="x y 127 - "+str+" 1 + * +",u=2, v=2)
- return (thinning == 0) ? thick : mt_merge(thin,thick,linemask,y=3,u=2,v=2)
- }
- function Camembert_dhh(clip input) {
- input
- SmoothUV(3,200,false)
- Overlay(last, Blur(1).Blur(1), mode="difference")
- GreyCenteredToMask_dhh().greyscale()
- Levels(0, 1, 115, 0, 255, false)
- mask1 = last
- Blur(1)
- Levels(0, 0.4, 64, 0, 255, false)
- mask = last
- Blur(1).Blur(1)
- Levels(0, 1, 30, 0, 255, false).Blur(1)
- mask2 = last
- return (mask2)
- }
- function Camembert_dhhMod(clip input)
- {
- EM1=input.Camembert_dhh()
- EM2=input.mt_edge(mode="min/max", thY1=1, thY2=255, thC1=10, thC2=10, chroma="process").mt_inflate().blur(1.5).blur(1.5).invert()
- return mt_logic(EM1, EM2, "and")
- }
- Function EMask_dhh(clip i, int mode, int trh)
- {
- e_mask = mode == 1 ? mt_makediff(i.blur(1.58).blur(1.58),i).mt_binarize(threshold=trh).mt_inflate().mt_inflate() :
- \ mode == 2 ? mt_logic(i.mt_binarize(105,upper=true).mt_expand(),i.mt_binarize(110,upper=false).mt_expand(),"and").mt_deflate() :
- \ mode == 3 ? mt_merge(i.mt_edge(mode="min/max", thY1=255, thY2=255), i.Camembert_dhh, i.FastLineDarkenMOD3_dhh(trh).blur(0.5).FastLineDarkenMOD3_dhh(250,1,250,-2).mt_binarize(70, mode="0 255")) : NOP()
- return e_mask
- }
- Function DR_Radius_dhh(clip i, int dr_rad, int count)
- {
- return count > dr_rad ? i : DR_Radius_dhh(i.mt_expand(), dr_rad, count+1)
- }
- Function DeHaloHmod(clip input, int "Radius", int "Str", bool "Maska", bool "strong", int "mode", int "thr", string "exdehalo", bool "analog", bool "dirty", bool "smooth", bool "anime", bool "pel2", bool "usedeen", bool "maskpel2")
- {
- usedeen = Default(usedeen, false)
- smooth = Default(smooth, false)
- strong = Default(strong, true)
- Maska = Default(Maska, false)
- analog = Default(analog, false)
- dirty = Default(dirty, false)
- DR_Radius = Default(Radius, dirty ? 6 : smooth ? 4 : 2)
- DR_Str = Default(Str, smooth ? 5 : usedeen ? 15 : 3)
- mode = Default(mode, usedeen ? 0 : 3)
- threshold = Default(thr, smooth ? 2250 : 140)
- anime = Default(anime, usedeen ? false : true)
- pel2 = Default(pel2, false)
- maskpel2 = Default(maskpel2, false)
- oclip = pel2 ? input.nnedi3_rpow2(rfactor=2) : input
- hfl = defined(exdehalo) ? eval("oclip." + exdehalo) : smooth ? oclip.DeHalo_alpha_mt(darkstr=0.2,brightstr=0.8).yahr2(dirty ? 8 : 16).TBilateral(DR_Str,5,0.9,0.9,5,5,0.7,chroma=false) : usedeen ? oclip.Deen("a2d", 2, DR_Str , 0, 0, 0, 0, 0) : oclip.TBilateral(DR_Str,5,0.9,0.9,5,5,0.7,chroma=false)
- hfl = pel2 && !(maskpel2 && dirty) ? hfl.PointResize(input.Width(),input.Height()) : hfl
- cm = dirty ? hfl : input
- cm = !(dirty && pel2) && maskpel2 ? cm.nnedi3_rpow2(rfactor=2) : cm
- EM1 = mode == 0 ? (strong ? Camembert_dhh(analog ? cm.ColorYUV(autogain=true) : cm) : Camembert_dhhMod(analog ? cm.ColorYUV(autogain=true) : cm)) : EMask_dhh(analog ? cm.ColorYUV(autogain=true) : cm, mode, threshold)
- EM1 = maskpel2 ? EM1.PointResize(input.Width(),input.Height()) : EM1
- hfl = pel2 && (maskpel2 && dirty) ? hfl.PointResize(input.Width(),input.Height()) : hfl
- RM2 = DR_Radius_dhh(EM1.mt_inflate(),DR_Radius,0).mt_inflate()
- DeRinging = anime ? mt_Merge(hfl, input, smooth ? EM1.mt_inflate(155,155) : EM1) : hfl
- DeRinging = Maska ? DeRinging.Invert() : DeRinging
- return mt_Merge(input, DeRinging, RM2, u=2, v=2)
- }
- Function DeHaloH(clip input, int "DR_Radius", int "DR_Str", bool "Maska", bool "strong", int "mode", int "threshold")
- {
- strong = Default(strong, true)
- Maska = Default(Maska, false)
- DR_Radius = Default(DR_Radius, 2)
- DR_Str = Default(DR_Str, 15)
- mode = Default(mode, 0)
- threshold = Default(threshold, 140)
- EM = mode == 0 ? (strong ? input.Camembert_dhh() : input.Camembert_dhhMod()) : EMask_dhh(input, mode, threshold)
- RM=DR_Radius_dhh(EM,DR_Radius,0)
- DeRinging = input.Deen("a2d", 2, DR_Str , 0, 0, 0, 0, 0)
- DeRinging = Maska ? DeRinging.Invert() : DeRinging
- return mt_Merge(input, DeRinging, RM)
- }
Add Comment
Please, Sign In to add comment