Advertisement
Guest User

RemoveDirtMC_SE

a guest
Nov 23rd, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #########################################################################################################################
  2. ###                                                                                                                   ###
  3. ###                                                  RemoveDirtMC                                                     ###
  4. ###                                                      v1.47                                                        ###
  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",float "rStr",float "Amp", bool "luma_rebuild", clip "PreNR")
  78.  
  79. {
  80.  
  81. version  = "v1.45"
  82.  
  83.      GPU = default(GPU,     true)
  84.   radius = default(radius,     2)
  85.  repmode = default(repmode,   16)
  86.   clmode = default(clmode,     5)
  87.  TwoPass = default(TwoPass, true)
  88.    thSAD = default(thSAD ,   150)
  89.   thSADC = default(thSADC, thSAD)
  90.    rStr  = default( rStr, 1.0 )
  91.    Amp   = default( Amp, 0.0625 )
  92. luma_rebuild = default(luma_rebuild, true)
  93.    
  94.       ox = input.width()
  95.       oy = input.height()
  96.       HD = (ox== 1920 || oy>= 800) ? true : false
  97.  blksize = (HD==true) ? 16:8
  98.   search = (HD==true) ?  4:5
  99.  overlap = blksize/2
  100.  
  101.          src = input
  102.        PreNR = defined(PreNR) ? PreNR : (GPU==true) ? src.NLMeansCL2(h=radius*1.5,u=3,v=3).TemporalDeGrain_SE(5,9) \
  103.                            : src.FFT3DFilter(sigma=radius*2,plane=4,bw=16,bh=16,ow=8,oh=8,bt=3,wintype=1).TemporalDeGrain_SE(5,9)
  104.        PreNR = luma_rebuild ? isyuy2(input) ? PreNR.Interleaved2Planar().dither_luma_rebuild(S0=rStr,c=Amp).Planar2Interleaved() \
  105.                            : PreNR.dither_luma_rebuild(S0=rStr,c=Amp) : PreNR
  106.  PreNR_super = MSuper(PreNR,hpad=4,vpad=4,pel=2,sharp=2)
  107.    src_super = MSuper(src  ,hpad=4,vpad=4,pel=2,sharp=2,levels=1)
  108.  
  109.  bwv1 = MAnalyse(PreNR_super, blksize=blksize, search=search, isb=true,  delta=1, overlap=overlap, truemotion=true)
  110.  bwv2 = (radius>=2) ? \
  111.     MAnalyse(PreNR_super, blksize=blksize, search=search, isb=true,  delta=2, overlap=overlap, truemotion=true) : BlankClip()
  112.  bwv3 = (radius==3) ? \
  113.     MAnalyse(PreNR_super, blksize=blksize, search=search, isb=true,  delta=3, overlap=overlap, truemotion=true) : BlankClip()
  114.  fwv1 = MAnalyse(PreNR_super, blksize=blksize, search=search, isb=false, delta=1, overlap=overlap, truemotion=true)
  115.  fwv2 = (radius>=2) ? \
  116.     MAnalyse(PreNR_super, blksize=blksize, search=search, isb=false, delta=2, overlap=overlap, truemotion=true) : BlankClip()
  117.  fwv3 = (radius==3) ? \
  118.     MAnalyse(PreNR_super, blksize=blksize, search=search, isb=false, delta=3, overlap=overlap, truemotion=true) : BlankClip()
  119.  
  120.  bcomp = MCompensate(src,src_super,bwv1)
  121.  fcomp = MCompensate(src,src_super,fwv1)
  122.  
  123.  NR1 = src.RemoveDirtSE(fcomp, bcomp, repmode=repmode, clmode=clmode)
  124.  NR1_super = ( TwoPass==true  ) ? MSuper(NR1,hpad=4,vpad=4,pel=2,sharp=2,levels=1) : BlankClip()
  125.        NR2 = ( TwoPass==false ) ? NR1
  126. \          : (  radius==1  ) ? MDeGrain1(NR1, NR1_super, bwv1, fwv1, thSAD=thSAD, thSADC=thSADC)
  127. \          : (  radius==2  ) ? MDeGrain2(NR1, NR1_super, bwv1, bwv2, fwv1, fwv2, thSAD=thSAD, thSADC=thSADC)
  128. \          :               MDeGrain3(NR1, NR1_super, bwv1, bwv2, bwv3, fwv1, fwv2, fwv3, thSAD=thSAD, thSADC=thSADC)
  129.     Return(NR2)
  130.  
  131. }
  132.  
  133. function TemporalDeGrain_SE(clip input, int "mode", int "thr")
  134.  
  135. {
  136. input = isYUY2(input) ? input.Interleaved2Planar() : input
  137.     mode = default(mode, 5)
  138.     thr  = default(thr,  8)
  139.     rg = RemoveGrain(input, mode=mode, Planar=true)
  140.     tr = TemporalRepair(rg, input, Planar=true)
  141. tr = isYUY2(input) ? tr.Planar2Interleaved() : tr
  142.         fs = FluxSmoothT(tr,thr)
  143.     Return(fs)
  144.      
  145. }
  146.  
  147. function RemoveDirtSE(clip input, clip fcomp, clip bcomp, int "repmode", int "clmode")
  148.  
  149. {
  150. input = isYUY2(input) ? input.Interleaved2Planar() : input
  151. fcomp = isYUY2(input) ? fcomp.Interleaved2Planar() : fcomp
  152. bcomp = isYUY2(input) ? bcomp.Interleaved2Planar() : bcomp
  153.      
  154.     repmode = default(repmode, 16)
  155.      clmode = default(clmode,   5)
  156.     clensed = interleave(fcomp,input,bcomp).Clense(cache=-1, Planar=true).selectevery(3,1)
  157.       clensedn2 = Clense(input, cache=-1, Planar=true)
  158.      sbegin = ForwardClense(input, cache=-1, Planar=true)
  159.        send = BackwardClense(input, cache=-1, Planar=true)
  160.         alt = Repair(SCSelect(input, sbegin, send, clensed, debug=false, Planar=true), input, mode=repmode, Planar=true)
  161.     restore = Repair(clensed, input, mode=repmode, Planar=true)
  162.       corrected = RestoreMotionBlocks(clensed, restore, neighbour=input, neighbour2=clensedn2, alternative=alt, gmthreshold=50, \
  163.                       dist=1, dmode=2, debug=false, noise=8, noisy=12, Planar=true)
  164.      postNR0 = clmode == 0 ? corrected : RemoveGrain(corrected, mode=clmode, Planar=true)
  165.      postNR1 = isYUY2(input) ? postNR0.Planar2Interleaved() : postNR0
  166.      Return(postNR1)
  167.    
  168. }
  169.  
  170.  
  171. function RemoveDirtMC_SE_nofade(clip input, int "cache")
  172. {
  173.     cache   = default(cache,10)
  174. input
  175. global rdcpm=0
  176. global rdnpm=0
  177. global rdcav=0
  178. global rdnav=0
  179. ScriptClip("""
  180. preb=Blur(1.5)
  181. 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))
  182.  
  183. cfr=current_frame
  184. rdppm=cfr<3 ? 0 : rdcpm
  185. global rdcpm=cfr<2 ? 0 : rdnpm
  186. global rdnpm=preb.trim(1,0).YPlaneMedian()
  187.  
  188. rdpav=cfr<3 ? 0 : rdcav
  189. global rdcav=cfr<2 ? 0 : rdnav
  190. global rdnav=preb.trim(1,0).AverageLuma()
  191.  
  192. fadedec=(rdcpm > rdnpm && rdcpm < rdppm) || (rdcpm < rdnpm && rdcpm > rdppm)
  193.  
  194. fadedec && (abs(rdcav-rdnav) < 12 && abs(rdcav-rdpav) < 12) ? last : RemoveDirtclip
  195.  
  196. """)
  197. cache<0 ? last : last.RequestLinear(8, cache, 5, false, false)
  198. }
  199.  
  200. function snofade(clip "o", clip "filtered", int "cache")
  201. {
  202.     cache   = default(cache,10)
  203. o
  204. global rdcpm=0
  205. global rdnpm=0
  206. global rdcav=0
  207. global rdnav=0
  208. global snofadeclip = filtered
  209. ScriptClip("""
  210. preb=Blur(1.5)
  211.  
  212. cfr=current_frame
  213. rdppm=cfr<3 ? 0 : rdcpm
  214. global rdcpm=cfr<2 ? 0 : rdnpm
  215. global rdnpm=preb.trim(1,0).YPlaneMedian()
  216.  
  217. rdpav=cfr<3 ? 0 : rdcav
  218. global rdcav=cfr<2 ? 0 : rdnav
  219. global rdnav=preb.trim(1,0).AverageLuma()
  220.  
  221. fadedec=(rdcpm > rdnpm && rdcpm < rdppm) || (rdcpm < rdnpm && rdcpm > rdppm)
  222.  
  223. fadedec && (abs(rdcav-rdnav) < 12 && abs(rdcav-rdpav) < 12) ? last : snofadeclip
  224.  
  225. """)
  226. cache<0 ? last : last.RequestLinear(8, cache, 5, false, false)
  227. }
  228.  
  229. function snofadeg(clip "o", clip "filtered")
  230. {
  231. o
  232. gScriptClip("""
  233. preb=Blur(1.5)
  234.  
  235. pav=preb.YPlaneMedian(-1)
  236. cav=preb.YPlaneMedian()
  237. nav=preb.YPlaneMedian(1)
  238.  
  239. fadedec=(cav > nav && cav < pav) || (cav < nav && cav > pav)
  240.  
  241. fadedec && (preb.YDifferenceToNext < 12 && preb.YDifferenceFromPrevious < 12) ? last : filtered
  242.  
  243. """, args="filtered")
  244. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement