SHOW:
|
|
- or go back to the newest paste.
1 | ######################################################################################################################### | |
2 | ### ### | |
3 | ### RemoveDirtMC ### | |
4 | - | ### v1.51 ### |
4 | + | ### v1.52 ### |
5 | ### **SPECIAL EDITION** ### | |
6 | ### By NEPHILIS ### | |
7 | ### @2011 ### | |
8 | ### mod by Great Dragon to work with NLMeansCL2 ### | |
9 | ### mod2 by A.SONY to make it more friendly in motions ### | |
10 | ######################################################################################################################### | |
11 | ||
12 | ################################################################## | |
13 | ## ## | |
14 | ## -------------- ## | |
15 | ## Requirements : - MVTools (v2.5.11.2) ## | |
16 | ## -------------- ## | |
17 | ## - RemoveGrainT (v1.0) package ## | |
18 | ## - RemoveDirt (v0.9) package ## | |
19 | ## - AvsRecursion (v0.2) ## | |
20 | ## - FluxSmooth (v1.1) ## | |
21 | ## ## | |
22 | ## As Additional ## | |
23 | ## -------- ## | |
24 | ## => To Prefiltering with FFT3DFilter ## | |
25 | ## - FFT3DFilter (v2.1.1) ## | |
26 | ## - Dither_Luma_Rebuild from SMDegrain or elsewhere ## | |
27 | ## -------- ## | |
28 | ## => To Prefiltering with NLMeansCL2 ## | |
29 | ## - NLMeansCL2.dll v0.4.0 (2015-01-08) ## | |
30 | ## ## | |
31 | ################################################################## | |
32 | ||
33 | ########################################################################################################################## | |
34 | # ------- # | |
35 | # Usage : # | |
36 | # ------- # | |
37 | # # | |
38 | # RemoveDirtMC_SE(clip input, bool"GPU", int"radius", int"repmode", int"clmode", bool"TwoPass", int"thSAD", int"thSADC") # | |
39 | # # | |
40 | ########################################################################################################################## | |
41 | ||
42 | ################## | |
43 | # ----------- # | |
44 | # PARAMETERS: # | |
45 | # ----------- # | |
46 | ################## | |
47 | ||
48 | ########################################################################################################################## | |
49 | # | |
50 | # ---------- | |
51 | # GPU : -- To choose NLMeansCL or FFT3Dfilter for PreFiltering process. | |
52 | # ---------- ATI GPU owners should use "GPU=false" | |
53 | # | |
54 | # ---------- | |
55 | # Radius : -- Temporal Radius for MDeGrain at second stage DeNoising. | |
56 | # ---------- | |
57 | # | |
58 | # ---------- | |
59 | # repmode : -- Repair mode value in main RemoveDirtSE function. | |
60 | # ---------- | |
61 | # | |
62 | # ---------- | |
63 | # clmode : -- RemoveGrain mode value in main RemoveDirtSE function. | |
64 | # ---------- | |
65 | # | |
66 | # ---------- | |
67 | # Twopass : -- To make a Temporal Denoising (MDeGrain) after Spatial Denoising (RemoveDirtSE). | |
68 | # ---------- | |
69 | # | |
70 | # ---------- | |
71 | # thSAD, | |
72 | # thSADC : -- MDeGrain's thSAD and thSADC parameters. | |
73 | # ---------- | |
74 | # | |
75 | ########################################################################################################################## | |
76 | ||
77 | - | Function RemoveDirtMC_SE(clip input, bool"GPU", int"radius", int"repmode", int"clmode", bool"TwoPass", int"thSAD", int"thSADC", int"resrepmode",float "rStr",float "Amp", bool "luma_rebuild", clip "PreNR", bool "recalculate", int "limit", bool "_grey", int "noisy", int "dist", int "gmthreshold", string "RDSE_params", int "mcthSAD", int "pel", int "thSCD1", int "thSCD2") |
77 | + | Function RemoveDirtMC_SE(clip input, bool"GPU", int"radius", int"repmode", int"clmode", bool"TwoPass", int"thSAD", int"thSADC", int"resrepmode",float "rStr",float "Amp", bool "luma_rebuild", clip "PreNR", bool "recalculate", int "limit", bool "_grey", int "noisy", int "dist", int "gmthreshold", string "RDSE_params", int "mcthSAD", int "pel", int "dct", int "thSCD1", int "thSCD2") |
78 | ||
79 | { | |
80 | ||
81 | - | version = "v1.51" |
81 | + | version = "v1.52" |
82 | ||
83 | GPU = default(GPU, true) | |
84 | _grey = default(_grey, false) | |
85 | radius = default(radius, 2) | |
86 | repmode = default(repmode, 16) | |
87 | clmode = default(clmode, 5) | |
88 | TwoPass = default(TwoPass, true) | |
89 | thSAD = default(thSAD , 150) | |
90 | thSAD2= thSAD/2 | |
91 | thSADC = default(thSADC, thSAD) | |
92 | rStr = default( rStr, 1.0) | |
93 | Amp = default( Amp, 0.0625) | |
94 | luma_rebuild = default(luma_rebuild, true) | |
95 | recalculate = default(recalculate, TwoPass) | |
96 | ||
97 | ox = input.width() | |
98 | oy = input.height() | |
99 | HD = (ox > 1099 || oy > 599) | |
100 | pel = default( pel, HD ? 1 : 2 ) | |
101 | blksize = HD ? 16 : 8 | |
102 | blksize2= int(blksize/2) + (int(blksize/2)%2) | |
103 | search = HD ? 4 : 5 | |
104 | overlap = blksize/2 | |
105 | overlap2= int(overlap/2) + (int(overlap/2)%2) | |
106 | ||
107 | src = input | |
108 | PreNR = defined(PreNR) ? PreNR : (GPU==true) ? src.NLMeansCL2(h=radius*1.5,u=3,v=3).TemporalDeGrain_SE(5,9,_grey=_grey) \ | |
109 | : src.FFT3DFilter(sigma=radius*2,plane=_grey ? 0 : 4,bw=16,bh=16,ow=8,oh=8,bt=3,wintype=1).TemporalDeGrain_SE(5,9,_grey=_grey) | |
110 | PreNR = luma_rebuild ? isyuy2(input) ? PreNR.Interleaved2Planar(_grey).dither_luma_rebuild(S0=rStr,c=Amp,uv=_grey ? 1 : 3).Planar2Interleaved(_grey) \ | |
111 | : PreNR.dither_luma_rebuild(S0=rStr,c=Amp,uv=_grey ? 1 : 3) : PreNR | |
112 | PreNR_super = MSuper(PreNR,hpad=4,vpad=4,pel=pel,sharp=2,chroma=!_grey) | |
113 | src_super = MSuper(src ,hpad=4,vpad=4,pel=pel,sharp=2,levels=1,chroma=!_grey) | |
114 | recalc_sup = recalculate ? MSuper(PreNR ,hpad=4,vpad=4,pel=pel,sharp=2,levels=1,chroma=!_grey) : nop() | |
115 | ||
116 | - | bwv1 = MAnalyse(PreNR_super, blksize=blksize, search=search, isb=true, delta=1, overlap=overlap, truemotion=true,chroma=!_grey) |
116 | + | bwv1 = MAnalyse(PreNR_super, blksize=blksize, search=search, isb=true, delta=1, dct=dct, overlap=overlap, truemotion=true,chroma=!_grey) |
117 | bwv2 = (radius>=2) ? \ | |
118 | - | MAnalyse(PreNR_super, blksize=blksize, search=search, isb=true, delta=2, overlap=overlap, truemotion=true,chroma=!_grey) : nop() |
118 | + | MAnalyse(PreNR_super, blksize=blksize, search=search, isb=true, delta=2, dct=dct, overlap=overlap, truemotion=true,chroma=!_grey) : nop() |
119 | bwv3 = (radius==3) ? \ | |
120 | - | MAnalyse(PreNR_super, blksize=blksize, search=search, isb=true, delta=3, overlap=overlap, truemotion=true,chroma=!_grey) : nop() |
120 | + | MAnalyse(PreNR_super, blksize=blksize, search=search, isb=true, delta=3, dct=dct, overlap=overlap, truemotion=true,chroma=!_grey) : nop() |
121 | - | fwv1 = MAnalyse(PreNR_super, blksize=blksize, search=search, isb=false, delta=1, overlap=overlap, truemotion=true,chroma=!_grey) |
121 | + | fwv1 = MAnalyse(PreNR_super, blksize=blksize, search=search, isb=false, delta=1, dct=dct, overlap=overlap, truemotion=true,chroma=!_grey) |
122 | fwv2 = (radius>=2) ? \ | |
123 | - | MAnalyse(PreNR_super, blksize=blksize, search=search, isb=false, delta=2, overlap=overlap, truemotion=true,chroma=!_grey) : nop() |
123 | + | MAnalyse(PreNR_super, blksize=blksize, search=search, isb=false, delta=2, dct=dct, overlap=overlap, truemotion=true,chroma=!_grey) : nop() |
124 | fwv3 = (radius==3) ? \ | |
125 | - | MAnalyse(PreNR_super, blksize=blksize, search=search, isb=false, delta=3, overlap=overlap, truemotion=true,chroma=!_grey) : nop() |
125 | + | MAnalyse(PreNR_super, blksize=blksize, search=search, isb=false, delta=3, dct=dct, overlap=overlap, truemotion=true,chroma=!_grey) : nop() |
126 | ||
127 | ||
128 | recalculate ? Eval(""" | |
129 | - | bwv1 = MRecalculate(recalc_sup,bwv1, blksize=blksize2, search=search, overlap=overlap2,thSAD=thSAD2, truemotion=true,chroma=!_grey) |
129 | + | bwv1 = MRecalculate(recalc_sup,bwv1, blksize=blksize2, search=search, dct=dct, overlap=overlap2,thSAD=thSAD2, truemotion=true,chroma=!_grey) |
130 | bwv2 = (radius>=2) ? \ | |
131 | - | MRecalculate(recalc_sup,bwv2, blksize=blksize2, search=search, overlap=overlap2,thSAD=thSAD2, truemotion=true,chroma=!_grey) : nop() |
131 | + | MRecalculate(recalc_sup,bwv2, blksize=blksize2, search=search, dct=dct, overlap=overlap2,thSAD=thSAD2, truemotion=true,chroma=!_grey) : nop() |
132 | bwv3 = (radius==3) ? \ | |
133 | - | MRecalculate(recalc_sup,bwv3, blksize=blksize2, search=search, overlap=overlap2,thSAD=thSAD2, truemotion=true,chroma=!_grey) : nop() |
133 | + | MRecalculate(recalc_sup,bwv3, blksize=blksize2, search=search, dct=dct, overlap=overlap2,thSAD=thSAD2, truemotion=true,chroma=!_grey) : nop() |
134 | - | fwv1 = MRecalculate(src_super,fwv1, blksize=blksize2, search=search, overlap=overlap2,thSAD=thSAD2, truemotion=true) |
134 | + | fwv1 = MRecalculate(recalc_sup,fwv1, blksize=blksize2, search=search, dct=dct, overlap=overlap2,thSAD=thSAD2, truemotion=true) |
135 | fwv2 = (radius>=2) ? \ | |
136 | - | MRecalculate(recalc_sup,fwv2, blksize=blksize2, search=search, overlap=overlap2,thSAD=thSAD2, truemotion=true,chroma=!_grey) : nop() |
136 | + | MRecalculate(recalc_sup,fwv2, blksize=blksize2, search=search, dct=dct, overlap=overlap2,thSAD=thSAD2, truemotion=true,chroma=!_grey) : nop() |
137 | fwv3 = (radius==3) ? \ | |
138 | - | MRecalculate(recalc_sup,fwv3, blksize=blksize2, search=search, overlap=overlap2,thSAD=thSAD2, truemotion=true,chroma=!_grey) : nop() |
138 | + | MRecalculate(recalc_sup,fwv3, blksize=blksize2, search=search, dct=dct, overlap=overlap2,thSAD=thSAD2, truemotion=true,chroma=!_grey) : nop() |
139 | """) : nop() | |
140 | ||
141 | ||
142 | bcomp = MCompensate(src,src_super,bwv1,thSAD=defined(mcthSAD) ? mcthSAD : TwoPass ? undefined : thSAD, thSCD1=thSCD1, thSCD2=thSCD2) | |
143 | fcomp = MCompensate(src,src_super,fwv1,thSAD=defined(mcthSAD) ? mcthSAD : TwoPass ? undefined : thSAD, thSCD1=thSCD1, thSCD2=thSCD2) | |
144 | ||
145 | NR1 = src.RemoveDirtSE(fcomp, bcomp, limit=limit, _grey=_grey, noisy=noisy, dist=dist, gmthreshold=gmthreshold, repmode=repmode, clmode=clmode, resrepmode=resrepmode, RDSE_params=RDSE_params) | |
146 | NR1_super = ( TwoPass==true ) ? MSuper(NR1,hpad=4,vpad=4,pel=pel,sharp=2,levels=1,chroma=!_grey) : nop() | |
147 | NR2 = ( TwoPass==false ) ? NR1 | |
148 | \ : ( radius==1 ) ? MDeGrain1(NR1, NR1_super, bwv1, fwv1, thSAD=thSAD, thSADC=thSADC,plane=_grey ? 0 : 4, thSCD1=thSCD1, thSCD2=thSCD2) | |
149 | \ : ( radius==2 ) ? MDeGrain2(NR1, NR1_super, bwv1, bwv2, fwv1, fwv2, thSAD=thSAD, thSADC=thSADC,plane=_grey ? 0 : 4, thSCD1=thSCD1, thSCD2=thSCD2) | |
150 | \ : MDeGrain3(NR1, NR1_super, bwv1, bwv2, bwv3, fwv1, fwv2, fwv3, thSAD=thSAD, thSADC=thSADC,plane=_grey ? 0 : 4, thSCD1=thSCD1, thSCD2=thSCD2) | |
151 | Return(NR2) | |
152 | ||
153 | } | |
154 | ||
155 | function TemporalDeGrain_SE(clip input, int "mode", int "thr", bool "_grey") | |
156 | ||
157 | { | |
158 | _grey = default(_grey, false) | |
159 | input = isYUY2(input) ? input.Interleaved2Planar(_grey) : input | |
160 | mode = default(mode, 5) | |
161 | thr = default(thr, 8) | |
162 | rg = RemoveGrain(input, mode=mode, modeU=_grey ? -1 : mode, Planar=true) | |
163 | tr = TemporalRepair(rg, input, grey=_grey, Planar=true) | |
164 | tr = isYUY2(input) ? tr.Planar2Interleaved(_grey) : tr | |
165 | fs = FluxSmoothT(tr,thr) | |
166 | Return(fs) | |
167 | ||
168 | } | |
169 | ||
170 | function RemoveDirtSE(clip input, clip fcomp, clip bcomp, int "limit", bool "_grey", int "noisy", int "dist", int "gmthreshold", int "repmode", int "clmode", int "resrepmode", string "RDSE_params") | |
171 | ||
172 | { | |
173 | _grey = default(_grey, false) | |
174 | limit = default(limit,8) | |
175 | noisy = default(noisy,12) | |
176 | dist = default(dist,1) | |
177 | gmthreshold = default(gmthreshold,50) | |
178 | RDSE_params = default(RDSE_params, "") # RestoreMotionBlocks | |
179 | input = isYUY2(input) ? input.Interleaved2Planar(_grey) : input | |
180 | fcomp = isYUY2(input) ? fcomp.Interleaved2Planar(_grey) : fcomp | |
181 | bcomp = isYUY2(input) ? bcomp.Interleaved2Planar(_grey) : bcomp | |
182 | ||
183 | repmode = default(repmode, 16) | |
184 | resrepmode = default(resrepmode,repmode) | |
185 | clmode = default(clmode, 5) | |
186 | clensed = interleave(fcomp,input,bcomp).Clense(cache=-1, grey=_grey, Planar=true).selectevery(3,1) | |
187 | clensedn2 = Clense(input, cache=-1, grey=_grey, Planar=true) | |
188 | sbegin = ForwardClense(input, cache=-1, grey=_grey, Planar=true) | |
189 | send = BackwardClense(input, cache=-1, grey=_grey, Planar=true) | |
190 | - | alt = Repair(SCSelect(input, sbegin, send, clensed, debug=false, Planar=true), input, mode=repmode, modeU=_grey ? -1 : repmode, Planar=true) |
190 | + | alt = SCSelect(input, sbegin, send, clensed, debug=false, Planar=true) |
191 | - | restore = Repair(clensed, input, mode=resrepmode, modeU=_grey ? -1 : resrepmode, Planar=true) |
191 | + | alt = repmode==0 ? alt : Repair(alt, input, mode=repmode, modeU=_grey ? -1 : repmode, Planar=true) |
192 | restore = resrepmode==0 ? clensed : Repair(clensed, input, mode=resrepmode, modeU=_grey ? -1 : resrepmode, Planar=true) | |
193 | corrected = Eval("RestoreMotionBlocks(clensed, restore, neighbour=input, neighbour2=clensedn2, alternative=alt, gmthreshold=gmthreshold, \ | |
194 | dist=dist, dmode=2, debug=false, noise=limit, noisy=noisy, grey=_grey, Planar=true" + RDSE_params + ")") | |
195 | postNR0 = clmode == 0 ? corrected : RemoveGrain(corrected, mode=clmode, modeU=_grey ? -1 : clmode, Planar=true) | |
196 | postNR1 = isYUY2(input) ? postNR0.Planar2Interleaved(_grey) : postNR0 | |
197 | Return(postNR1) | |
198 | ||
199 | } | |
200 | ||
201 | ||
202 | function RemoveDirtMC_SE_nofade(clip input, int "cache") | |
203 | { | |
204 | cache = default(cache,10) | |
205 | input | |
206 | global rdcpm=0 | |
207 | global rdnpm=0 | |
208 | global rdcav=0 | |
209 | global rdnav=0 | |
210 | ScriptClip(""" | |
211 | preb=Blur(1.5) | |
212 | RemoveDirtclip=RemoveDirtMC_SE(twopass=false,clmode=0,rstr=1.5,PreNR=FFT3DFilter(sigma=4,plane=4,bw=16,bh=16,ow=8,oh=8,bt=3,wintype=1).ColorYUV(autogain=true).TemporalDeGrain_SE(5,9)) | |
213 | ||
214 | cfr=current_frame | |
215 | rdppm=cfr<3 ? 0 : rdcpm | |
216 | global rdcpm=cfr<2 ? 0 : rdnpm | |
217 | global rdnpm=preb.trim(1,0).YPlaneMedian() | |
218 | ||
219 | rdpav=cfr<3 ? 0 : rdcav | |
220 | global rdcav=cfr<2 ? 0 : rdnav | |
221 | global rdnav=preb.trim(1,0).AverageLuma() | |
222 | ||
223 | fadedec=(rdcpm > rdnpm && rdcpm < rdppm) || (rdcpm < rdnpm && rdcpm > rdppm) | |
224 | ||
225 | fadedec && (abs(rdcav-rdnav) < 12 && abs(rdcav-rdpav) < 12) ? last : RemoveDirtclip | |
226 | ||
227 | """) | |
228 | cache<0 ? last : last.RequestLinear(8, cache, 5, false, false) | |
229 | } | |
230 | ||
231 | function snofade(clip "o", clip "filtered", int "cache") | |
232 | { | |
233 | cache = default(cache,10) | |
234 | o | |
235 | global rdcpm=0 | |
236 | global rdnpm=0 | |
237 | global rdcav=0 | |
238 | global rdnav=0 | |
239 | global snofadeclip = filtered | |
240 | ScriptClip(""" | |
241 | preb=Blur(1.5) | |
242 | ||
243 | cfr=current_frame | |
244 | rdppm=cfr<3 ? 0 : rdcpm | |
245 | global rdcpm=cfr<2 ? 0 : rdnpm | |
246 | global rdnpm=preb.trim(1,0).YPlaneMedian() | |
247 | ||
248 | rdpav=cfr<3 ? 0 : rdcav | |
249 | global rdcav=cfr<2 ? 0 : rdnav | |
250 | global rdnav=preb.trim(1,0).AverageLuma() | |
251 | ||
252 | fadedec=(rdcpm > rdnpm && rdcpm < rdppm) || (rdcpm < rdnpm && rdcpm > rdppm) | |
253 | ||
254 | fadedec && (abs(rdcav-rdnav) < 12 && abs(rdcav-rdpav) < 12) ? last : snofadeclip | |
255 | ||
256 | """) | |
257 | cache<0 ? last : last.RequestLinear(8, cache, 5, false, false) | |
258 | } | |
259 | ||
260 | function snofadeg(clip "o", clip "filtered") | |
261 | { | |
262 | o | |
263 | gScriptClip(""" | |
264 | preb=Blur(1.5) | |
265 | ||
266 | pav=preb.YPlaneMedian(-1) | |
267 | cav=preb.YPlaneMedian() | |
268 | nav=preb.YPlaneMedian(1) | |
269 | ||
270 | fadedec=(cav > nav && cav < pav) || (cav < nav && cav > pav) | |
271 | ||
272 | fadedec && (preb.YDifferenceToNext < 12 && preb.YDifferenceFromPrevious < 12) ? last : filtered | |
273 | ||
274 | """, args="filtered") | |
275 | } |