View difference between Paste ID: fZi29eWM and RWvyA9Ek
SHOW: | | - or go back to the newest paste.
1
#########################################################################################################################
2
###                                                                                                                   ###
3
###                                                  RemoveDirtMC                                                     ###
4-
###                                                      v1.42                                                        ###
4+
###                                                      v1.43                                                        ###
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
## --------------  - Masktools    (v2.0a48)                     ##
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-
##         - FFTW3.dll                                          ##
26+
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 "slices", bool "luma_rebuild", clip "PreNR")
78
79
{
80
81
version  = "v1.43"
82-
version  = "v1.42"
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
slices   = default(slices, true)
93
luma_rebuild = default(luma_rebuild, true)
94
    
95
      ox = input.width()
96
      oy = input.height()
97
      HD = (ox== 1920 || oy>= 800) ? true : false
98
 blksize = (HD==true) ? 16:8
99
  search = (HD==true) ?  4:5
100
 overlap = blksize/2
101
102
         src = input
103
       PreNR = defined(PreNR) ? PreNR : (GPU==true) ? src.NLMeansCL2(h=radius*1.5,u=3,v=3).TemporalDeGrain_SE(5,9) \
104
                           : src.FFT3DFilter(sigma=radius*2,plane=4,bw=16,bh=16,ow=8,oh=8,bt=3,wintype=1).TemporalDeGrain_SE(5,9)
105
       PreNR = luma_rebuild ? PreNR.dither_luma_rebuild(S0=rStr,c=Amp,slice=slices) : 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
	mode = default(mode, 5)
137
	thr  = default(thr,  8)
138
	rg = RemoveGrain(input, mode=mode)
139
	tr = TemporalRepair(rg, input)
140
        fs = FluxSmoothT(tr,thr)
141
	Return(fs)
142
	 
143
}
144
145
function RemoveDirtSE(clip input, clip fcomp, clip bcomp, int "repmode", int "clmode")
146
147
{
148
      
149
	repmode = default(repmode, 16)
150
	 clmode = default(clmode,   5)
151
	clensed = interleave(fcomp,input,bcomp).Clense(cache=-1).selectevery(3,1)
152
      clensedn2 = Clense(input, cache=-1)
153
	 sbegin = ForwardClense(input, cache=-1)
154
	   send = BackwardClense(input, cache=-1)
155
	    alt = Repair(SCSelect(input, sbegin, send, clensed, debug=false), input, mode=repmode) 
156
	restore = Repair(clensed, input, mode=repmode)
157
      corrected = RestoreMotionBlocks(clensed, restore, neighbour=input, neighbour2=clensedn2, alternative=alt, gmthreshold=50, \
158
				      dist=1, dmode=2, debug=false, noise=8, noisy=12)
159
	 postNR = clmode == 0 ? corrected : RemoveGrain(corrected, mode=clmode)
160-
	 postNR = RemoveGrain(corrected, mode=clmode)
160+
161
	
162
}