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