Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # DeHaloHmod v.2.39
- function GreyCenteredToMask_dhh(clip input) {
- # Levels will convert to lut in avs26 by this "x input_low - input_high input_low - / 1 gamma / ^ output_high output_low - * output_low +"
- VersionNumber() < 2.6 ? input.Levels(128, 1, 255, 0, 255, false) : input.mt_lut("x range_half - range_max range_half - / range_max 0 - * 0 +")
- one = last
- VersionNumber() < 2.6 ? input.Levels(0, 1, 128, 255, 0, false) : input.mt_lut("x 0 - range_half 0 - / 0 range_max - * range_max +")
- two = last
- Overlay(one, two, mode="lighten")
- }
- function FastLineDarkenMOD3_dhh( clip input, float "strength", float "prot", float "luma_cap", float "threshold", float "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.)
- Assert(!(input.isrgb()), "FastLineDarkenMOD4: RGB Color formats is not supported" )
- ssispmt = Findstr(VersionString(), "AviSynth+") != 0 && Findstr(VersionString(), "r1576") == 0
- sislumaonly = ssispmt ? input.isy() : VersionNumber() < 2.6 ? true : input.isy8()
- c = sislumaonly ? input : ssispmt ? input.converttoy() : input.converttoy8()
- ## filtering ##
- exin = c.mt_expand(thy=255/(protection+1)).mt_inpand()
- diff = VersionNumber() < 2.6 ? mt_lutxy(c,exin,yexpr="y "+lum+" < y "+lum+" ? x "+thr+" + > x y "+lum+" < y "+lum+" ? - 0 ? 127 +",uexpr="x",vexpr="x")
- \ : mt_lutxy(c,exin,yexpr="y "+lum+" scalef < y "+lum+" scalef ? x "+thr+" scalef + > x y "+lum+" scalef < y "+lum+" scalef ? - 0 ? 127 scalef +")
- linemask= thinning != 0 ? VersionNumber() < 2.6 ? mt_lut(diff.mt_inpand(),"x 127 - "+thn+" * 255 +").mt_convolution("1 1 1","1 1 1")
- \ : mt_lut(diff.mt_inpand(),"clamp_f_i8 x 127 scalef - "+thn+" * range_max +").mt_convolution("1 1 1","1 1 1") : nop()
- thick = VersionNumber() < 2.6 ? 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)
- \ : mt_lutxy(c, exin, yexpr="clamp_f_i8 y "+lum+" scalef < y "+lum+" scalef ? x "+thr+" scalef + > x y "+lum+" scalef < y "+lum+" scalef ? - 0 ? "+str+" * x +",u=2, v=2)
- thin = thinning != 0 ? VersionNumber() < 2.6 ? mt_lutxy(c.mt_expand(U=2,V=2),diff,yexpr="x y 127 - "+str+" 1 + * +",u=2, v=2)
- \ : mt_lutxy(c.mt_expand(U=2,V=2),diff,yexpr="clamp_f_i8 x y 127 scalef - "+str+" 1 + * +",u=2, v=2) : nop()
- thinning == 0 ? thick : mt_merge(thin,thick,linemask,y=3,u=2,v=2)
- return sislumaonly ? last : ssispmt ? CombinePlanes(last,input,planes="YUV",sample_clip=input) : ytouv(input.utoy8(),input.vtoy8(),last)
- }
- function Camembert_dhh(clip input, int "useMedianBlur", bool "honly", bool "lumaonly") {
- lumaonly = default(lumaonly, false)
- useMedianBlur = default(useMedianBlur, lumaonly ? -1 : 0)
- honly = default(honly, false)
- ssispmt = Findstr(VersionString(), "AviSynth+") != 0 && Findstr(VersionString(), "r1576") == 0
- sislumaonly = ssispmt ? input.isy() : VersionNumber() < 2.6 ? true : input.isy8()
- useMedianBlur = sislumaonly && !(VersionNumber() < 2.6) ? -1 : useMedianBlur
- c = sislumaonly || !lumaonly ? input : ssispmt ? input.converttoy() : input.converttoy8()
- c
- useMedianBlur==0 ? SmoothUV(3,200,false) : useMedianBlur>0 ? MedianBlur(0,useMedianBlur,useMedianBlur) : last
- Overlay(last, Blur(1,honly ? 0 : 1).Blur(1,honly ? 0 : 1), mode="difference")
- grsc=sislumaonly ? nop() : GreyCenteredToMask_dhh().greyscale()
- sislumaonly ? GreyCenteredToMask_dhh() : ssispmt ? grsc.converttoy() : grsc.converttoy8()
- VersionNumber() < 2.6 ? greyscale() : last
- VersionNumber() < 2.6 ? Levels(0, 1, 115, 0, 255, false) : mt_lut("x 0 - 155 scalef 0 - / range_max 0 - * 0 +")
- Blur(1,honly ? 0 : 1)
- VersionNumber() < 2.6 ? Levels(0, 0.4, 64, 0, 255, false) : mt_lut("x 0 - 64 scalef 0 - / 1 0.4 / ^ range_max 0 - * 0 +")
- Blur(1,honly ? 0 : 1).Blur(1,honly ? 0 : 1)
- VersionNumber() < 2.6 ? Levels(0, 1, 30, 0, 255, false).Blur(1,honly ? 0 : 1) : mt_lut("x 0 - 30 scalef 0 - / range_max 0 - * 0 +",u=3,v=3).Blur(1,honly ? 0 : 1)
- sislumaonly ? last : ssispmt ? CombinePlanes(last,lumaonly ? input : grsc,planes="YUV",sample_clip=lumaonly ? input : grsc) : YToUV(lumaonly ? input.UToY8() : grsc.UToY8(),lumaonly ? input.VToY8() : grsc.VToY8(),last)
- }
- function Camembert_dhhMod(clip input, int "useMedianBlur", bool "honly", bool "lumaonly")
- {
- EM1=input.Camembert_dhh(useMedianBlur,honly,lumaonly)
- 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", float "trh", bool "analog", float "trh2", int "useMedianBlur", bool "honly", bool "lumaonly")
- {
- analog = Default(analog, false)
- trh2 = Default(trh2, 170)
- useMedianBlur = default(useMedianBlur, -1)
- mode3thr1 = mode == 3 && analog ? trh2/2.46 : nop()
- mode3dark = mode == 3 ? trh != 0 ? i.FastLineDarkenMOD3_dhh(trh).blur(0.5).FastLineDarkenMOD3_dhh(250,1,250,-2) : i : nop()
- mode3lut = mode == 3 && analog ? VersionNumber() < 2.6 ? "x "+String(mode3thr1)+" < 255 x "+String(trh2)+" > 0 255 x "+String(mode3thr1)+" - 255 "+String(trh2)+" "+String(mode3thr1)+" - / * - ? ?"
- \ : "x "+String(mode3thr1)+" scalef < range_max x "+String(trh2)+" scalef > 0 range_max x "+String(mode3thr1)+" scalef - range_max "+String(trh2)+" scalef "+String(mode3thr1)+" scalef - / * - ? ?" : nop()
- 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 ? analog ? mt_merge(i.mt_edge(mode="min/max", thY1=255, thY2=255), i.Camembert_dhh(useMedianBlur,honly,lumaonly), mode3dark.mt_lut(mode3lut,u=1,v=1)) :
- \ mt_merge(i.mt_edge(mode="min/max", thY1=255, thY2=255), i.Camembert_dhh(useMedianBlur,honly,lumaonly), mode3dark.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 DRadius_dhh(clip i, int "dr_rad")
- {
- return dr_rad > 0 ? DRadius_dhh(i.mt_expand(), dr_rad-1).mt_inflate() : i
- }
- Function DeHaloHmod(clip input, int "Radius", int "Str", bool "Maska", bool "strong", int "mode", float "thr", val "exdehalo", bool "analog", bool "dirty", bool "smooth", bool "anime", bool "pel2", bool "usedeen", bool "maskpel2", float "thr2", val "extmask", val "extlmask", bool "RadInflate")
- {
- usedeen = Default(usedeen, false)
- pel2 = Default(pel2, false)
- exdhcb = defined(exdehalo) ? isclip(exdehalo) ? true : false : false
- pel2 = exdhcb ? false : pel2
- maskpel2 = Default(maskpel2, false)
- exhmcb = defined(extmask) ? isclip(extmask) ? true : false : false
- exhlmcb = defined(extlmask) ? isclip(extlmask) ? true : false : false
- maskpel2 = exhmcb ? false : pel2
- smooth = Default(smooth, false)
- RadInflate = Default(RadInflate, false)
- strong = Default(strong, true)
- Maska = Default(Maska, false)
- analog = Default(analog, false)
- dirty = Default(dirty, false)
- DR_Radius = Default(Radius, defined(extlmask) ? -2 : dirty ? 6 : smooth || maskpel2 ? 4 : 2)
- DR_Str = Default(Str, usedeen ? pel2 ? 40 : 15 : pel2 ? 7 : smooth ? 5 : 3)
- mode = Default(mode, usedeen || defined(extlmask) ? 0 : 3)
- threshold = Default(thr, smooth ? mode==1 ? 1 : 2250 : 140)
- anime = Default(anime, defined(extlmask) ? true : mode != 3 ? false : true)
- thr2 = Default(thr2, smooth ? 170 : threshold/1.5)
- oclip = pel2 ? input.nnedi3_rpow2(rfactor=2) : input
- hfl = defined(exdehalo) ? exdhcb ? exdehalo : eval("oclip." + exdehalo) : smooth ? oclip.DeHalo_alpha_mt(rx=pel2 ? 3 : 2,ry=pel2 ? 3 : 2,darkstr=0.2,brightstr=0.8).yahr2(dirty ? pel2 ? 12 : 8 : pel2 ? 24 : 16).TBilateral(DR_Str,5,pel2 ? 1.4 : 0.9,0.9,pel2 ? 7 : 5,5,0.7,chroma=false) : usedeen ? oclip.Deen("a2d", 2, DR_Str , 0, 0, 0, 0, 0) : oclip.TBilateral(DR_Str,5,pel2 ? 1.4 : 0.9,0.9,pel2 ? 7 : 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
- extmask = defined(extmask) ? exhmcb ? extmask : Eval("cm." + extmask) : undefined()
- extlmask = defined(extlmask) ? exhlmcb ? extlmask : Eval("cm." + extlmask) : undefined()
- EM1 = defined(extmask) ? extmask : mode == 0 ? (strong ? Camembert_dhh(analog ? cm.ColorYUV(autogain=true) : cm, 3) : Camembert_dhhMod(analog ? cm.ColorYUV(autogain=true) : cm, 3)) : EMask_dhh(analog ? cm.ColorYUV(autogain=true) : cm, mode, threshold, analog, thr2, 3)
- EM1 = maskpel2 ? EM1.PointResize(input.Width(),input.Height()) : EM1
- hfl = pel2 && (maskpel2 && dirty) ? hfl.PointResize(input.Width(),input.Height()) : hfl
- RM2 = DR_Radius < -1 ? EM1 : RadInflate ? DRadius_dhh(EM1,DR_Radius).mt_inflate() : DR_Radius_dhh(EM1.mt_inflate(),DR_Radius,0).mt_inflate()
- LiMa = defined(extlmask) ? extlmask : EM1
- DeRinging = anime ? mt_Merge(hfl, input, smooth ? LiMa.mt_inflate(155,155) : LiMa) : 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)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement