# DeHaloHmod 27 8 2014 http://forum.doom9.org/showthread.php?p=1675762#post1675762 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") { strong = Default(strong, true) Maska = Default(Maska, false) DR_Radius_dhh = Default(Radius, 2) DR_Str = Default(Str, 3) mode = Default(mode, 3) threshold = Default(thr, 140) EM1 = mode == 0 ? (strong ? input.Camembert_dhh() : input.Camembert_dhhMod()) : EMask_dhh(input, mode, threshold) RM2 = DR_Radius_dhh(EM1.mt_inflate(),DR_Radius_dhh,0).mt_inflate() DeRinging = mt_Merge(input.TBilateral(DR_Str,5,0.9,0.9,5,5,0.7), input, EM1) DeRinging = Maska ? DeRinging.Invert() : DeRinging return mt_Merge(input, DeRinging, RM2) } 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) }