Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #########################################################################################################################
- ### ###
- ### RemoveDirtMC ###
- ### v1.45 ###
- ### **SPECIAL EDITION** ###
- ### By NEPHILIS ###
- ### @2011 ###
- ### mod by Great Dragon to work with NLMeansCL2 ###
- ### mod2 by A.SONY to make it more friendly in motions ###
- #########################################################################################################################
- ##################################################################
- ## ##
- ## -------------- ##
- ## Requirements : - MVTools (v2.5.11.2) ##
- ## -------------- ##
- ## - RemoveGrainT (v1.0) package ##
- ## - RemoveDirt (v0.9) package ##
- ## - AvsRecursion (v0.2) ##
- ## - FluxSmooth (v1.1) ##
- ## ##
- ## As Additional ##
- ## -------- ##
- ## => To Prefiltering with FFT3DFilter ##
- ## - FFT3DFilter (v2.1.1) ##
- ## - Dither_Luma_Rebuild from SMDegrain or elsewhere ##
- ## -------- ##
- ## => To Prefiltering with NLMeansCL2 ##
- ## - NLMeansCL2.dll v0.4.0 (2015-01-08) ##
- ## ##
- ##################################################################
- ##########################################################################################################################
- # ------- #
- # Usage : #
- # ------- #
- # #
- # RemoveDirtMC_SE(clip input, bool"GPU", int"radius", int"repmode", int"clmode", bool"TwoPass", int"thSAD", int"thSADC") #
- # #
- ##########################################################################################################################
- ##################
- # ----------- #
- # PARAMETERS: #
- # ----------- #
- ##################
- ##########################################################################################################################
- #
- # ----------
- # GPU : -- To choose NLMeansCL or FFT3Dfilter for PreFiltering process.
- # ---------- ATI GPU owners should use "GPU=false"
- #
- # ----------
- # Radius : -- Temporal Radius for MDeGrain at second stage DeNoising.
- # ----------
- #
- # ----------
- # repmode : -- Repair mode value in main RemoveDirtSE function.
- # ----------
- #
- # ----------
- # clmode : -- RemoveGrain mode value in main RemoveDirtSE function.
- # ----------
- #
- # ----------
- # Twopass : -- To make a Temporal Denoising (MDeGrain) after Spatial Denoising (RemoveDirtSE).
- # ----------
- #
- # ----------
- # thSAD,
- # thSADC : -- MDeGrain's thSAD and thSADC parameters.
- # ----------
- #
- ##########################################################################################################################
- Function RemoveDirtMC_SE(clip input, bool"GPU", int"radius", int"repmode", int"clmode", bool"TwoPass", int"thSAD", int"thSADC",float "rStr",float "Amp", bool "luma_rebuild", clip "PreNR")
- {
- version = "v1.45"
- GPU = default(GPU, true)
- radius = default(radius, 2)
- repmode = default(repmode, 16)
- clmode = default(clmode, 5)
- TwoPass = default(TwoPass, true)
- thSAD = default(thSAD , 150)
- thSADC = default(thSADC, thSAD)
- rStr = default( rStr, 1.0 )
- Amp = default( Amp, 0.0625 )
- luma_rebuild = default(luma_rebuild, true)
- ox = input.width()
- oy = input.height()
- HD = (ox== 1920 || oy>= 800) ? true : false
- blksize = (HD==true) ? 16:8
- search = (HD==true) ? 4:5
- overlap = blksize/2
- src = input
- PreNR = defined(PreNR) ? PreNR : (GPU==true) ? src.NLMeansCL2(h=radius*1.5,u=3,v=3).TemporalDeGrain_SE(5,9) \
- : src.FFT3DFilter(sigma=radius*2,plane=4,bw=16,bh=16,ow=8,oh=8,bt=3,wintype=1).TemporalDeGrain_SE(5,9)
- PreNR = luma_rebuild ? isyuy2(input) ? PreNR.Interleaved2Planar().dither_luma_rebuild(S0=rStr,c=Amp).Planar2Interleaved() \
- : PreNR.dither_luma_rebuild(S0=rStr,c=Amp) : PreNR
- PreNR_super = MSuper(PreNR,hpad=4,vpad=4,pel=2,sharp=2)
- src_super = MSuper(src ,hpad=4,vpad=4,pel=2,sharp=2,levels=1)
- bwv1 = MAnalyse(PreNR_super, blksize=blksize, search=search, isb=true, delta=1, overlap=overlap, truemotion=true)
- bwv2 = (radius>=2) ? \
- MAnalyse(PreNR_super, blksize=blksize, search=search, isb=true, delta=2, overlap=overlap, truemotion=true) : BlankClip()
- bwv3 = (radius==3) ? \
- MAnalyse(PreNR_super, blksize=blksize, search=search, isb=true, delta=3, overlap=overlap, truemotion=true) : BlankClip()
- fwv1 = MAnalyse(PreNR_super, blksize=blksize, search=search, isb=false, delta=1, overlap=overlap, truemotion=true)
- fwv2 = (radius>=2) ? \
- MAnalyse(PreNR_super, blksize=blksize, search=search, isb=false, delta=2, overlap=overlap, truemotion=true) : BlankClip()
- fwv3 = (radius==3) ? \
- MAnalyse(PreNR_super, blksize=blksize, search=search, isb=false, delta=3, overlap=overlap, truemotion=true) : BlankClip()
- bcomp = MCompensate(src,src_super,bwv1)
- fcomp = MCompensate(src,src_super,fwv1)
- NR1 = src.RemoveDirtSE(fcomp, bcomp, repmode=repmode, clmode=clmode)
- NR1_super = ( TwoPass==true ) ? MSuper(NR1,hpad=4,vpad=4,pel=2,sharp=2,levels=1) : BlankClip()
- NR2 = ( TwoPass==false ) ? NR1
- \ : ( radius==1 ) ? MDeGrain1(NR1, NR1_super, bwv1, fwv1, thSAD=thSAD, thSADC=thSADC)
- \ : ( radius==2 ) ? MDeGrain2(NR1, NR1_super, bwv1, bwv2, fwv1, fwv2, thSAD=thSAD, thSADC=thSADC)
- \ : MDeGrain3(NR1, NR1_super, bwv1, bwv2, bwv3, fwv1, fwv2, fwv3, thSAD=thSAD, thSADC=thSADC)
- Return(NR2)
- }
- function TemporalDeGrain_SE(clip input, int "mode", int "thr")
- {
- input = isYUY2(input) ? input.Interleaved2Planar() : input
- mode = default(mode, 5)
- thr = default(thr, 8)
- rg = RemoveGrain(input, mode=mode, Planar=true)
- tr = TemporalRepair(rg, input, Planar=true)
- tr = isYUY2(input) ? tr.Planar2Interleaved() : tr
- fs = FluxSmoothT(tr,thr)
- Return(fs)
- }
- function RemoveDirtSE(clip input, clip fcomp, clip bcomp, int "repmode", int "clmode")
- {
- input = isYUY2(input) ? input.Interleaved2Planar() : input
- fcomp = isYUY2(input) ? fcomp.Interleaved2Planar() : fcomp
- bcomp = isYUY2(input) ? bcomp.Interleaved2Planar() : bcomp
- repmode = default(repmode, 16)
- clmode = default(clmode, 5)
- clensed = interleave(fcomp,input,bcomp).Clense(cache=-1, Planar=true).selectevery(3,1)
- clensedn2 = Clense(input, cache=-1, Planar=true)
- sbegin = ForwardClense(input, cache=-1, Planar=true)
- send = BackwardClense(input, cache=-1, Planar=true)
- alt = Repair(SCSelect(input, sbegin, send, clensed, debug=false, Planar=true), input, mode=repmode, Planar=true)
- restore = Repair(clensed, input, mode=repmode, Planar=true)
- corrected = RestoreMotionBlocks(clensed, restore, neighbour=input, neighbour2=clensedn2, alternative=alt, gmthreshold=50, \
- dist=1, dmode=2, debug=false, noise=8, noisy=12, Planar=true)
- postNR0 = clmode == 0 ? corrected : RemoveGrain(corrected, mode=clmode, Planar=true)
- postNR1 = isYUY2(input) ? postNR0.Planar2Interleaved() : postNR0
- Return(postNR1)
- }
- function RemoveDirtMC_SE_nofade(clip input)
- {
- input
- ScriptClip("""
- preb=Blur(1.5)
- 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))
- pcl=preb.trim(0,-1)+preb.trim(0,0)
- nav=preb.trim(1,0).YPlaneMedian()
- pav=pcl.YPlaneMedian()
- cav=preb.YPlaneMedian()
- fadedec=(cav > nav && cav < pav) || (cav < nav && cav > pav)
- fadedec && (preb.YDifferenceToNext < 12 && preb.YDifferenceFromPrevious < 12) ? last : RemoveDirtclip
- """)
- }
- function snofade(clip "o", clip "filtered")
- {
- o
- global snofadeclip = filtered
- ScriptClip("""
- preb=Blur(1.5)
- pcl=preb.trim(0,-1)+preb.trim(0,0)
- nav=preb.trim(1,0).YPlaneMedian()
- pav=pcl.YPlaneMedian()
- cav=preb.YPlaneMedian()
- fadedec=(cav > nav && cav < pav) || (cav < nav && cav > pav)
- fadedec && (preb.YDifferenceToNext < 12 && preb.YDifferenceFromPrevious < 12) ? last : snofadeclip
- """)
- }
Add Comment
Please, Sign In to add comment