View difference between Paste ID: BAfXZBth and uSmZqapf
SHOW: | | - or go back to the newest paste.
1-
# DeHaloHmod v.2.37
1+
# DeHaloHmod v.2.38
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 +")
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 +")
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 +")
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()
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)
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()
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") {
49
50
useMedianBlur = default(useMedianBlur, 0)
51
52
ssispmt   = Findstr(VersionString(), "AviSynth+") != 0 && Findstr(VersionString(), "r1576") == 0
53
sislumaonly = ssispmt ? input.isy() : VersionNumber() < 2.6 ? true : input.isy8()
54
55
useMedianBlur = sislumaonly && !(VersionNumber() < 2.6) ? -1 : useMedianBlur
56
57
input
58
useMedianBlur==0 ? SmoothUV(3,200,false) : useMedianBlur>0 ? MedianBlur(0,useMedianBlur,useMedianBlur) : last
59
Overlay(last, Blur(1).Blur(1), mode="difference")
60
grsc=sislumaonly ? nop() : GreyCenteredToMask_dhh().greyscale()
61
sislumaonly ? GreyCenteredToMask_dhh() : ssispmt ? grsc.converttoy() : grsc.converttoy8()
62
VersionNumber() < 2.6 ? greyscale() : last
63
VersionNumber() < 2.6 ? Levels(0, 1, 115, 0, 255, false) : mt_lut("x 0 - 155 scalef 0 - / range_max 0 - * 0 +")
64
Blur(1)
65
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 +")
66
Blur(1).Blur(1)
67
VersionNumber() < 2.6 ? Levels(0, 1, 30, 0, 255, false).Blur(1) : mt_lut("x 0 - 30 scalef 0 - / range_max 0 - * 0 +").Blur(1)
68
sislumaonly ? last : ssispmt ? CombinePlanes(last,grsc,planes="YUV",sample_clip=grsc) : YToUV(grsc.UToY8(),grsc.vToY8(),last)
69
}
70
71
function Camembert_dhhMod(clip input, int "useMedianBlur")
72
{
73
 EM1=input.Camembert_dhh(useMedianBlur)
74
 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()
75
 return mt_logic(EM1, EM2, "and")
76
}
77
78
Function EMask_dhh(clip i, int "mode", float "trh", bool "analog", float "trh2", int "useMedianBlur")
79
{
80
analog        = Default(analog, false)
81
trh2          = Default(trh2, 170)
82
useMedianBlur = default(useMedianBlur, -1)
83
mode3thr1     = mode == 3 && analog ? trh2/2.46 : nop()
84
mode3dark     = mode == 3 ? trh != 0 ? i.FastLineDarkenMOD3_dhh(trh).blur(0.5).FastLineDarkenMOD3_dhh(250,1,250,-2) : i : nop()
85
mode3lut      = mode == 3 && analog ? VersionNumber() < 2.6 ? "x "+String(mode3thr1)+" < 255 x "+String(trh2)+" > 0 255 x "+String(mode3thr1)+" - 255 "+String(trh2)+" "+String(mode3thr1)+" - / * - ? ?"
86
                                      \                     : "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()
87
e_mask = mode == 1 ? mt_makediff(i.blur(1.58).blur(1.58),i).mt_binarize(threshold=trh).mt_inflate().mt_inflate() :
88-
     \   mode == 3 ? analog ? mt_merge(i.mt_edge(mode="min/max", thY1=255, thY2=255), i.Camembert_dhh(useMedianBlur), i.FastLineDarkenMOD3_dhh(trh).blur(0.5).FastLineDarkenMOD3_dhh(250,1,250,-2).mt_lut(mode3lut,u=1,v=1)) :
88+
89-
                            \ mt_merge(i.mt_edge(mode="min/max", thY1=255, thY2=255), i.Camembert_dhh(useMedianBlur), i.FastLineDarkenMOD3_dhh(trh).blur(0.5).FastLineDarkenMOD3_dhh(250,1,250,-2).mt_binarize(70, mode="0 255")) : NOP()
89+
     \   mode == 3 ? analog ? mt_merge(i.mt_edge(mode="min/max", thY1=255, thY2=255), i.Camembert_dhh(useMedianBlur), mode3dark.mt_lut(mode3lut,u=1,v=1)) :
90
                            \ mt_merge(i.mt_edge(mode="min/max", thY1=255, thY2=255), i.Camembert_dhh(useMedianBlur), mode3dark.mt_binarize(70, mode="0 255")) : NOP()
91
return e_mask
92
}
93
94
Function DR_Radius_dhh(clip i, int dr_rad, int count)
95
{
96
return count > dr_rad ? i : DR_Radius_dhh(i.mt_expand(), dr_rad, count+1)
97
}
98
99
Function DRadius_dhh(clip i, int "dr_rad")
100
{
101
return dr_rad > 0 ? DRadius_dhh(i.mt_expand(), dr_rad-1).mt_inflate() : i
102
}
103
104
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")
105
{
106
 usedeen    = Default(usedeen, false)
107
 pel2       = Default(pel2, false)
108
 exdhcb     = defined(exdehalo) ? isclip(exdehalo) ? true : false : false
109
 pel2       = exdhcb ? false : pel2
110
 maskpel2   = Default(maskpel2, false)
111
 exhmcb     = defined(extmask) ? isclip(extmask) ? true : false : false
112
 exhlmcb    = defined(extlmask) ? isclip(extlmask) ? true : false : false
113
 maskpel2   = exhmcb ? false : pel2
114
 smooth     = Default(smooth, false)
115
 RadInflate = Default(RadInflate, false)
116
 strong     = Default(strong, true)
117
 Maska      = Default(Maska, false)
118
 analog     = Default(analog, false)
119
 dirty      = Default(dirty, false)
120
 DR_Radius  = Default(Radius, defined(extlmask) ? -2 : dirty ? 6 : smooth || maskpel2 ? 4 : 2)
121
 DR_Str     = Default(Str, usedeen ? pel2 ? 40 : 15 : pel2 ? 7 : smooth ? 5 : 3)
122
 mode       = Default(mode, usedeen || defined(extlmask) ? 0 : 3)
123
 threshold  = Default(thr, smooth ? mode==1 ? 1 : 2250 : 140)
124
 anime      = Default(anime, defined(extlmask) ? true : mode != 3 ? false : true)
125
 thr2       = Default(thr2, smooth ? 170 : threshold/1.5)
126
127
 oclip = pel2 ? input.nnedi3_rpow2(rfactor=2) : input
128
 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)
129
 hfl = pel2 && !(maskpel2 && dirty) ? hfl.PointResize(input.Width(),input.Height()) : hfl
130
131
 cm  = dirty ? hfl : input
132
133
 cm  = !(dirty && pel2) && maskpel2 ? cm.nnedi3_rpow2(rfactor=2) : cm
134
135
 extmask = defined(extmask) ? exhmcb ? extmask : Eval("cm." + extmask) : undefined()
136
137
 extlmask = defined(extlmask) ? exhlmcb ? extlmask : Eval("cm." + extlmask) : undefined()
138
139
 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)
140
141
 EM1 = maskpel2 ? EM1.PointResize(input.Width(),input.Height()) : EM1
142
143
 hfl = pel2 && (maskpel2 && dirty) ? hfl.PointResize(input.Width(),input.Height()) : hfl
144
145
 RM2 = DR_Radius < -1 ? EM1 : RadInflate ? DRadius_dhh(EM1,DR_Radius).mt_inflate() : DR_Radius_dhh(EM1.mt_inflate(),DR_Radius,0).mt_inflate()
146
147
 LiMa = defined(extlmask) ? extlmask : EM1
148
149
 DeRinging = anime ? mt_Merge(hfl, input, smooth ? LiMa.mt_inflate(155,155) : LiMa) : hfl
150
 DeRinging = Maska ? DeRinging.Invert() : DeRinging
151
152
return mt_Merge(input, DeRinging, RM2, u=2, v=2)
153
}
154
155
Function DeHaloH(clip input, int "DR_Radius", int "DR_Str", bool "Maska", bool "strong", int "mode", int "threshold")
156
{
157
 strong     = Default(strong, true)
158
 Maska      = Default(Maska, false)
159
 DR_Radius  = Default(DR_Radius, 2)
160
 DR_Str     = Default(DR_Str, 15)
161
 mode       = Default(mode, 0)
162
 threshold  = Default(threshold, 140)
163
164
 EM = mode == 0 ? (strong ? input.Camembert_dhh() : input.Camembert_dhhMod()) : EMask_dhh(input, mode, threshold)
165
166
 RM=DR_Radius_dhh(EM,DR_Radius,0)
167
 DeRinging  = input.Deen("a2d", 2, DR_Str  , 0, 0, 0, 0, 0)
168
 DeRinging = Maska ?  DeRinging.Invert() : DeRinging
169
return mt_Merge(input, DeRinging, RM)
170
}