SHOW:
|
|
- or go back to the newest paste.
1 | - | # DeHaloHmod v.2.40 |
1 | + | # DeHaloHmod v.2.41 |
2 | ||
3 | function GreyCenteredToMask_dhh(clip input) { | |
4 | # Levels will convert to lut in avs26 by this "x input_low - input_high input_low - / 1 gamma / ^ output_high output_low - * output_low +" | |
5 | - | 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 +") |
5 | + | 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 +", use_expr=2) |
6 | one = last | |
7 | - | VersionNumber() < 2.6 ? input.Levels(0, 1, 128, 255, 0, false) : input.mt_lut("x 0 - range_half 0 - / 0 range_max - * range_max +") |
7 | + | VersionNumber() < 2.6 ? input.Levels(0, 1, 128, 255, 0, false) : input.mt_lut("x 0 - range_half 0 - / 0 range_max - * range_max +", use_expr=2) |
8 | two = last | |
9 | Overlay(one, two, mode="lighten") | |
10 | } | |
11 | ||
12 | ||
13 | function FastLineDarkenMOD3_dhh( clip input, float "strength", float "prot", float "luma_cap", float "threshold", float "thinning") | |
14 | { | |
15 | ## parameters ## | |
16 | str = string(default(strength, 48) /128.) | |
17 | lum = string(default(luma_cap, 191)) | |
18 | protection = default(prot,5) | |
19 | thr = string(default(threshold, 4)) | |
20 | thinning = default(thinning,0) | |
21 | thn = string(thinning /16.) | |
22 | ||
23 | Assert(!(input.isrgb()), "FastLineDarkenMOD4: RGB Color formats is not supported" ) | |
24 | ||
25 | ssispmt = Findstr(VersionString(), "AviSynth+") != 0 && Findstr(VersionString(), "r1576") == 0 | |
26 | ||
27 | sislumaonly = ssispmt ? input.isy() : VersionNumber() < 2.6 ? true : input.isy8() | |
28 | ||
29 | c = sislumaonly ? input : ssispmt ? input.converttoy() : input.converttoy8() | |
30 | ||
31 | ## filtering ## | |
32 | exin = c.mt_expand(thy=255/(protection+1)).mt_inpand() | |
33 | 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") | |
34 | - | \ : mt_lutxy(c,exin,yexpr="y "+lum+" scalef < y "+lum+" scalef ? x "+thr+" scalef + > x y "+lum+" scalef < y "+lum+" scalef ? - 0 ? 127 scalef +") |
34 | + | \ : mt_lutxy(c,exin,yexpr="y "+lum+" scalef < y "+lum+" scalef ? x "+thr+" scalef + > x y "+lum+" scalef < y "+lum+" scalef ? - 0 ? 127 scalef +", use_expr=2) |
35 | linemask= thinning != 0 ? VersionNumber() < 2.6 ? mt_lut(diff.mt_inpand(),"x 127 - "+thn+" * 255 +").mt_convolution("1 1 1","1 1 1") | |
36 | - | \ : mt_lut(diff.mt_inpand(),"clamp_f_i8 x 127 scalef - "+thn+" * range_max +").mt_convolution("1 1 1","1 1 1") : nop() |
36 | + | \ : mt_lut(diff.mt_inpand(),"x 127 scalef - "+thn+" * range_max +", scale_inputs="floatf", use_expr=2).mt_convolution("1 1 1","1 1 1") : nop() |
37 | 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) | |
38 | - | \ : 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) |
38 | + | \ : mt_lutxy(c, exin, yexpr="y "+lum+" scalef < y "+lum+" scalef ? x "+thr+" scalef + > x y "+lum+" scalef < y "+lum+" scalef ? - 0 ? "+str+" * x +", scale_inputs="floatf", use_expr=2,u=2, v=2) |
39 | 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) | |
40 | - | \ : 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() |
40 | + | \ : mt_lutxy(c.mt_expand(U=2,V=2),diff,yexpr="x y 127 scalef - "+str+" 1 + * +",scale_inputs="floatf", use_expr=2,u=2, v=2) : nop() |
41 | ||
42 | thinning == 0 ? thick : mt_merge(thin,thick,linemask,y=3,u=2,v=2) | |
43 | ||
44 | return sislumaonly ? last : ssispmt ? CombinePlanes(last,input,planes="YUV",sample_clip=input) : ytouv(input.utoy8(),input.vtoy8(),last) | |
45 | } | |
46 | ||
47 | ||
48 | function Camembert_dhh(clip input, int "useMedianBlur", bool "honly", bool "lumaonly") { | |
49 | ||
50 | lumaonly = default(lumaonly, false) | |
51 | useMedianBlur = default(useMedianBlur, lumaonly ? -1 : 0) | |
52 | honly = default(honly, false) | |
53 | ||
54 | ssispmt = Findstr(VersionString(), "AviSynth+") != 0 && Findstr(VersionString(), "r1576") == 0 | |
55 | sislumaonly = ssispmt ? input.isy() : VersionNumber() < 2.6 ? true : input.isy8() | |
56 | ||
57 | useMedianBlur = sislumaonly && !(VersionNumber() < 2.6) ? -1 : useMedianBlur | |
58 | ||
59 | c = sislumaonly || !lumaonly ? input : ssispmt ? input.converttoy() : input.converttoy8() | |
60 | ||
61 | c | |
62 | useMedianBlur==0 ? SmoothUV(3,200,false) : useMedianBlur>0 ? MedianBlur(0,useMedianBlur,useMedianBlur) : last | |
63 | Overlay(last, Blur(1,honly ? 0 : 1).Blur(1,honly ? 0 : 1), mode="difference") | |
64 | grsc=sislumaonly ? nop() : GreyCenteredToMask_dhh().greyscale() | |
65 | sislumaonly ? GreyCenteredToMask_dhh() : ssispmt ? grsc.converttoy() : grsc.converttoy8() | |
66 | VersionNumber() < 2.6 ? greyscale() : last | |
67 | - | VersionNumber() < 2.6 ? Levels(0, 1, 115, 0, 255, false) : mt_lut("x 0 - 155 scalef 0 - / range_max 0 - * 0 +") |
67 | + | VersionNumber() < 2.6 ? Levels(0, 1, 115, 0, 255, false) : mt_lut("x 0 - 155 scalef 0 - / range_max 0 - * 0 +", use_expr=2) |
68 | Blur(1,honly ? 0 : 1) | |
69 | - | 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 +") |
69 | + | 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 +", use_expr=2) |
70 | Blur(1,honly ? 0 : 1).Blur(1,honly ? 0 : 1) | |
71 | - | 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) |
71 | + | 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 +", use_expr=2,u=3,v=3).Blur(1,honly ? 0 : 1) |
72 | 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) | |
73 | } | |
74 | ||
75 | function Camembert_dhhMod(clip input, int "useMedianBlur", bool "honly", bool "lumaonly") | |
76 | { | |
77 | EM1=input.Camembert_dhh(useMedianBlur,honly,lumaonly) | |
78 | 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() | |
79 | return mt_logic(EM1, EM2, "and") | |
80 | } | |
81 | ||
82 | Function EMask_dhh(clip oi, int "mode", float "trh", bool "analog", float "trh2", int "useMedianBlur", bool "honly", bool "lumaonly") | |
83 | { | |
84 | analog = Default(analog, false) | |
85 | trh2 = Default(trh2, 170) | |
86 | lumaonly = default(lumaonly, false) | |
87 | useMedianBlur = default(useMedianBlur, lumaonly ? -1 : 0) | |
88 | honly = default(honly, false) | |
89 | ||
90 | ssispmt = Findstr(VersionString(), "AviSynth+") != 0 && Findstr(VersionString(), "r1576") == 0 | |
91 | sislumaonly = ssispmt ? oi.isy() : VersionNumber() < 2.6 ? true : oi.isy8() | |
92 | ||
93 | i = sislumaonly || !lumaonly ? oi : ssispmt ? oi.converttoy() : oi.converttoy8() | |
94 | ||
95 | mode3thr1 = mode == 3 && analog ? trh2/2.46 : nop() | |
96 | mode3dark = mode == 3 ? trh != 0 ? i.FastLineDarkenMOD3_dhh(trh).blur(0.5).FastLineDarkenMOD3_dhh(250,1,250,-2) : i : nop() | |
97 | mode3lut = mode == 3 && analog ? VersionNumber() < 2.6 ? "x "+String(mode3thr1)+" < 255 x "+String(trh2)+" > 0 255 x "+String(mode3thr1)+" - 255 "+String(trh2)+" "+String(mode3thr1)+" - / * - ? ?" | |
98 | \ : "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() | |
99 | e_mask = mode == 1 ? mt_makediff(i.blur(1.58).blur(1.58),i).mt_binarize(threshold=trh).mt_inflate().mt_inflate() : | |
100 | \ mode == 2 ? mt_logic(i.mt_binarize(105,upper=true).mt_expand(),i.mt_binarize(110,upper=false).mt_expand(),"and").mt_deflate() : | |
101 | - | \ 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)) : |
101 | + | \ mode == 3 ? analog ? mt_merge(i.mt_edge(mode="min/max", thY1=255, thY2=255), i.Camembert_dhh(useMedianBlur,honly,lumaonly), VersionNumber() < 2.6 ? mode3dark.mt_lut(mode3lut,u=1,v=1) : mode3dark.mt_lut(mode3lut,use_expr=2,u=1,v=1)) : |
102 | \ 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() | |
103 | e_mask = sislumaonly ? e_mask : ssispmt ? CombinePlanes(e_mask,oi,planes="YUV",sample_clip=oi) : YToUV(oi.UToY8(),oi.VToY8(),e_mask) | |
104 | return e_mask | |
105 | } | |
106 | ||
107 | Function DR_Radius_dhh(clip i, int dr_rad, int count) | |
108 | { | |
109 | return count > dr_rad ? i : DR_Radius_dhh(i.mt_expand(), dr_rad, count+1) | |
110 | } | |
111 | ||
112 | Function DRadius_dhh(clip i, int "dr_rad") | |
113 | { | |
114 | return dr_rad > 0 ? DRadius_dhh(i.mt_expand(), dr_rad-1).mt_inflate() : i | |
115 | } | |
116 | ||
117 | 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") | |
118 | { | |
119 | usedeen = Default(usedeen, false) | |
120 | pel2 = Default(pel2, false) | |
121 | exdhcb = defined(exdehalo) ? isclip(exdehalo) ? true : false : false | |
122 | pel2 = exdhcb ? false : pel2 | |
123 | maskpel2 = Default(maskpel2, false) | |
124 | exhmcb = defined(extmask) ? isclip(extmask) ? true : false : false | |
125 | exhlmcb = defined(extlmask) ? isclip(extlmask) ? true : false : false | |
126 | maskpel2 = exhmcb ? false : pel2 | |
127 | smooth = Default(smooth, false) | |
128 | RadInflate = Default(RadInflate, false) | |
129 | strong = Default(strong, true) | |
130 | Maska = Default(Maska, false) | |
131 | analog = Default(analog, false) | |
132 | dirty = Default(dirty, false) | |
133 | DR_Radius = Default(Radius, defined(extlmask) ? -2 : dirty ? 6 : smooth || maskpel2 ? 4 : 2) | |
134 | DR_Str = Default(Str, usedeen ? pel2 ? 40 : 15 : pel2 ? 7 : smooth ? 5 : 3) | |
135 | mode = Default(mode, usedeen || defined(extlmask) ? 0 : 3) | |
136 | threshold = Default(thr, smooth ? mode==1 ? 1 : 2250 : 140) | |
137 | anime = Default(anime, defined(extlmask) ? true : mode != 3 ? false : true) | |
138 | thr2 = Default(thr2, smooth ? 170 : threshold/1.5) | |
139 | ||
140 | oclip = pel2 ? input.nnedi3_rpow2(rfactor=2) : input | |
141 | 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) | |
142 | hfl = pel2 && !(maskpel2 && dirty) ? hfl.PointResize(input.Width(),input.Height()) : hfl | |
143 | ||
144 | cm = dirty ? hfl : input | |
145 | ||
146 | cm = !(dirty && pel2) && maskpel2 ? cm.nnedi3_rpow2(rfactor=2) : cm | |
147 | ||
148 | extmask = defined(extmask) ? exhmcb ? extmask : Eval("cm." + extmask) : undefined() | |
149 | ||
150 | extlmask = defined(extlmask) ? exhlmcb ? extlmask : Eval("cm." + extlmask) : undefined() | |
151 | ||
152 | 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) | |
153 | ||
154 | EM1 = maskpel2 ? EM1.PointResize(input.Width(),input.Height()) : EM1 | |
155 | ||
156 | hfl = pel2 && (maskpel2 && dirty) ? hfl.PointResize(input.Width(),input.Height()) : hfl | |
157 | ||
158 | RM2 = DR_Radius < -1 ? EM1 : RadInflate ? DRadius_dhh(EM1,DR_Radius).mt_inflate() : DR_Radius_dhh(EM1.mt_inflate(),DR_Radius,0).mt_inflate() | |
159 | ||
160 | LiMa = defined(extlmask) ? extlmask : EM1 | |
161 | ||
162 | DeRinging = anime ? mt_Merge(hfl, input, smooth ? LiMa.mt_inflate(155,155) : LiMa) : hfl | |
163 | DeRinging = Maska ? DeRinging.Invert() : DeRinging | |
164 | ||
165 | return mt_Merge(input, DeRinging, RM2, u=2, v=2) | |
166 | } | |
167 | ||
168 | Function DeHaloH(clip input, int "DR_Radius", int "DR_Str", bool "Maska", bool "strong", int "mode", int "threshold") | |
169 | { | |
170 | strong = Default(strong, true) | |
171 | Maska = Default(Maska, false) | |
172 | DR_Radius = Default(DR_Radius, 2) | |
173 | DR_Str = Default(DR_Str, 15) | |
174 | mode = Default(mode, 0) | |
175 | threshold = Default(threshold, 140) | |
176 | ||
177 | EM = mode == 0 ? (strong ? input.Camembert_dhh() : input.Camembert_dhhMod()) : EMask_dhh(input, mode, threshold) | |
178 | ||
179 | RM=DR_Radius_dhh(EM,DR_Radius,0) | |
180 | DeRinging = input.Deen("a2d", 2, DR_Str , 0, 0, 0, 0, 0) | |
181 | DeRinging = Maska ? DeRinging.Invert() : DeRinging | |
182 | return mt_Merge(input, DeRinging, RM) | |
183 | } |