View difference between Paste ID: RWvyA9Ek and cJYXT1RM
SHOW: | | - or go back to the newest paste.
1
#########################################################################################################################
2
###                                                                                                                   ###
3
###                                                  RemoveDirtMC                                                     ###
4-
###                                                      v1.41                                                        ###
4+
###                                                      v1.42                                                        ###
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                                ###
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                                          ##
27
##         - Dither_Luma_Rebuild from SMDegrain or elsewhere    ##
28
##              --------                                        ##
29
##        => To Prefiltering with NLMeansCL2                    ##
30
##         - NLMeansCL2.dll v0.4.0 (2015-01-08)                 ##
31
##                                                              ##
32
##################################################################
33
34
##########################################################################################################################
35
# -------                                                                                                                #
36
# Usage :                                                                                                                #
37
# -------                                                                                                                #
38
#                                                                                                                        #
39
# RemoveDirtMC_SE(clip input, bool"GPU", int"radius", int"repmode", int"clmode", bool"TwoPass", int"thSAD", int"thSADC") #
40
#                                                                                                                        #
41
##########################################################################################################################
42
43
##################
44
# -----------    #
45
# PARAMETERS:    #
46
# -----------    #
47
##################
48
49
##########################################################################################################################
50
#
51
# ----------
52
# GPU       : -- To choose NLMeansCL or FFT3Dfilter for PreFiltering process.
53
# ----------     ATI GPU owners should use "GPU=false" 
54
#	     	      
55
# ----------
56
# Radius    : -- Temporal Radius for MDeGrain at second stage DeNoising.
57
# ----------
58
#
59
# ----------
60
# repmode   : -- Repair mode value in main RemoveDirtSE function.
61
# ----------     
62
#
63
# ----------
64
# clmode    : -- RemoveGrain mode value in main RemoveDirtSE function.
65
# ----------
66
#
67
# ----------
68
# Twopass   : -- To make a Temporal Denoising (MDeGrain) after Spatial Denoising (RemoveDirtSE).   
69
# ----------   
70
#
71
# ----------
72
# thSAD, 
73
# thSADC    : -- MDeGrain's thSAD and thSADC parameters.
74
# ---------- 
75
#
76
##########################################################################################################################
77
78
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")
79
80
{
81
82-
version  = "v1.4"
82+
version  = "v1.42"
83
84
     GPU = default(GPU,     true)
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
  thSADC = default(thSADC, thSAD)
91
   rStr  = default( rStr, 1.0 )
92
   Amp   = default( Amp, 0.0625 )
93
slices   = default(slices, true)
94
luma_rebuild = default(luma_rebuild, true)
95
    
96
      ox = input.width()
97
      oy = input.height()
98
      HD = (ox== 1920 || oy>= 800) ? true : false
99
 blksize = (HD==true) ? 16:8
100
  search = (HD==true) ?  4:5
101
 overlap = blksize/2
102
103
         src = input
104-
       PreNR = defined(PreNR) ? PreNR : (GPU==true) ? src.NLMeansCL2(h=radius*1.5,u=3,v=3).TemporalDeGrain(5,9) \
104+
       PreNR = defined(PreNR) ? PreNR : (GPU==true) ? src.NLMeansCL2(h=radius*1.5,u=3,v=3).TemporalDeGrain_SE(5,9) \
105-
                           : src.FFT3DFilter(sigma=radius*2,plane=4,bw=16,bh=16,ow=8,oh=8,bt=3,wintype=1).TemporalDeGrain(5,9)
105+
                           : src.FFT3DFilter(sigma=radius*2,plane=4,bw=16,bh=16,ow=8,oh=8,bt=3,wintype=1).TemporalDeGrain_SE(5,9)
106
       PreNR = luma_rebuild ? PreNR.dither_luma_rebuild(S0=rStr,c=Amp,slice=slices) : PreNR
107
 PreNR_super = MSuper(PreNR,hpad=4,vpad=4,pel=2,sharp=2)
108
   src_super = MSuper(src  ,hpad=4,vpad=4,pel=2,sharp=2,levels=1)
109
110
 bwv1 = MAnalyse(PreNR_super, blksize=blksize, search=search, isb=true,  delta=1, overlap=overlap, truemotion=true) 
111
 bwv2 = (radius>=2) ? \
112
	MAnalyse(PreNR_super, blksize=blksize, search=search, isb=true,  delta=2, overlap=overlap, truemotion=true) : BlankClip()
113
 bwv3 = (radius==3) ? \
114
	MAnalyse(PreNR_super, blksize=blksize, search=search, isb=true,  delta=3, overlap=overlap, truemotion=true) : BlankClip()
115
 fwv1 = MAnalyse(PreNR_super, blksize=blksize, search=search, isb=false, delta=1, overlap=overlap, truemotion=true) 
116
 fwv2 = (radius>=2) ? \
117
	MAnalyse(PreNR_super, blksize=blksize, search=search, isb=false, delta=2, overlap=overlap, truemotion=true) : BlankClip()
118
 fwv3 = (radius==3) ? \
119
	MAnalyse(PreNR_super, blksize=blksize, search=search, isb=false, delta=3, overlap=overlap, truemotion=true) : BlankClip()
120
121
 bcomp = MCompensate(src,src_super,bwv1) 
122
 fcomp = MCompensate(src,src_super,fwv1)
123
  
124
 NR1 = src.RemoveDirtSE(fcomp, bcomp, repmode=repmode, clmode=clmode)
125
 NR1_super = ( TwoPass==true  ) ? MSuper(NR1,hpad=4,vpad=4,pel=2,sharp=2,levels=1) : BlankClip()
126
       NR2 = ( TwoPass==false ) ? NR1
127
\   	   : (  radius==1  ) ? MDeGrain1(NR1, NR1_super, bwv1, fwv1, thSAD=thSAD, thSADC=thSADC)
128
\   	   : (  radius==2  ) ? MDeGrain2(NR1, NR1_super, bwv1, bwv2, fwv1, fwv2, thSAD=thSAD, thSADC=thSADC)
129
\   	   : 		       MDeGrain3(NR1, NR1_super, bwv1, bwv2, bwv3, fwv1, fwv2, fwv3, thSAD=thSAD, thSADC=thSADC)
130
 	Return(NR2)
131
132
}
133
134-
function TemporalDeGrain(clip input, int "mode", int "thr")
134+
function TemporalDeGrain_SE(clip input, int "mode", int "thr")
135
136
{
137
	mode = default(mode, 5)
138
	thr  = default(thr,  8)
139
	rg = RemoveGrain(input, mode=mode)
140
	tr = TemporalRepair(rg, input)
141
        fs = FluxSmoothT(tr,thr)
142
	Return(fs)
143
	 
144
}
145
146
function RemoveDirtSE(clip input, clip fcomp, clip bcomp, int "repmode", int "clmode")
147
148
{
149
      
150
	repmode = default(repmode, 16)
151
	 clmode = default(clmode,   5)
152
	clensed = interleave(fcomp,input,bcomp).Clense(cache=-1).selectevery(3,1)
153
      clensedn2 = Clense(input, cache=-1)
154
	 sbegin = ForwardClense(input, cache=-1)
155
	   send = BackwardClense(input, cache=-1)
156
	    alt = Repair(SCSelect(input, sbegin, send, clensed, debug=false), input, mode=repmode) 
157
	restore = Repair(clensed, input, mode=repmode)
158
      corrected = RestoreMotionBlocks(clensed, restore, neighbour=input, neighbour2=clensedn2, alternative=alt, gmthreshold=50, \
159
				      dist=1, dmode=2, debug=false, noise=8, noisy=12)
160
	 postNR = RemoveGrain(corrected, mode=clmode)
161
	 Return(postNR)
162
	
163
}