Advertisement
Guest User

restoration filter-chain

a guest
Feb 12th, 2019
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Avisynth 10.85 KB | None | 0 0
  1. # 8mm film restoration script by videoFred.
  2. # www.super-8.be
  3. # info@super-8.be
  4.  
  5. # version 01.B with frame blending
  6. # release date: june 20, 2012
  7. #============================================================================================
  8.  
  9. # august 2010: added removerdirtMC() as suggested by John Meyer
  10. # october 2010: auto sharpening parameters
  11.  
  12. # march 2011: new autolevels.dll by Jim Battle
  13. # www.thebattles.net/video/autolevels.html
  14.  
  15. # june 2012: improved stabilisation
  16.  
  17. #=============================================================================================
  18.  
  19. # cleaning, degraining, resizing, stabilizing, sharpening, auto-levels and auto-white balance.
  20. #=============================================================================================
  21.  
  22.  
  23. film= "C:\Users\alojal\Desktop\AvsPmod\IN\10.mp4"  # source clip, you must specify the full path here
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32. #PARAMETERS
  33. #----------------------------------------------------------------------------------------------------------------------------
  34. result="resultS1" # specify the wanted output here
  35.  
  36. trim_begin=2  trim_end=16 play_speed= 18.75  #trim frames and play speed (PAL: 16.6666 or 18.75)
  37.  
  38. final_framerate = 25  # final frame rate
  39.  
  40. frame_blend= 0.4 # set this lover for less blending
  41.  
  42.  
  43. #COLOR AND LEVELS PARAMATERS
  44. #----------------------------------------------------------------------------------------------------------------------------
  45. saturation=1.2   #for all outputs
  46. gamma= 1.2 # for all outputs
  47.  
  48. blue= -0  red= 0  #manual color adjustment, when returning result3 or result4. Values can be positive or negative
  49.  
  50.  
  51. black_level=0  white_level=255 output_black=0  output_white=255 # manual levels, when returning result4
  52.  
  53.  
  54.  
  55. #AUTO LEVELS PARAMETERS
  56. #--------------------------------------------------------------------------------------------------------------------------------
  57.  
  58. autolev_low= 4     # limit of autolevels low output
  59. autolev_high= 240  # limit of autolevels high output
  60.  
  61.  
  62.  
  63.  
  64. #SIZE, CROP AND BORDERS PARAMETERS
  65. #----------------------------------------------------------------------------------------------------------------------------
  66. CLeft=20  CTop=20  CRight=20  CBottom=20  #crop values after Depan and before final resizing
  67.  
  68. W=720  H=576  #final size after cropping
  69.  
  70. bord_left=0  bord_top=0  bord_right=0  bord_bot=0 #720p= borders 150
  71.  
  72.  
  73. #STABILISING PARAMETERS, YOU REALY MUST USE RESULTS7 TO CHECK STABILISATION!
  74. #----------------------------------------------------------------------------------------------------------------------------
  75. maxstabH=20
  76. maxstabV=20 #maximum values for the stabiliser (in pixels) 20 is a good start value
  77.  
  78. est_left=40   est_top=40  est_right=40  est_bottom=40  #crop values for special Estimate clip
  79.  
  80. trust_value= 1.0     # scene change detection, higher= more sensitive
  81. cutoff_value= 0.5   # no need to change this, but you can play with it and see what you get
  82.  
  83.  
  84.  
  85. #CLEANING PARAMETERS
  86. #--------------------------------------------------------------------------------------------------------------
  87. dirt_strenght=30  # set this lower for clean films.
  88.  
  89.  
  90. #DENOISING PARAMETERS
  91. #----------------------------------------------------------------------------------------------------------------------------
  92.  
  93.  
  94. denoising_strenght= 300  #denoising level of second denoiser: MVDegrainMulti()
  95. denoising_frames= 2  #number of frames for averaging (forwards and backwards) 3 is a good start value
  96. block_size= 16  #block size of MVDegrainMulti()
  97. block_size_v= 16
  98. block_over= 8  #block overlapping of MVDegrainMulti()
  99.  
  100.  
  101.  
  102.  
  103. # FOUR STEP SHARPENING PARAMETERS
  104. #--------------------------------------------------------------------------------------------------------------------------------
  105.  
  106. USM_sharp_ness= 40   USM_radi_us= 3  #this is the start value for the unsharpmask sharpening
  107.                                      #do not set radius less then 3
  108.                                      #the script will automatically add two other steps with lower radius
  109.  
  110.  
  111.  
  112.  
  113. last_sharp= 0.1 #final sharpening step after degraining and before blending
  114.  
  115.  last_blur= 0.0 #this smooths out the heavy sharpening effects
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122. # END VARIABLES, BEGIN SCRIPT
  123. #=================================================================================================================================
  124.  
  125.  
  126. SetMemoryMax(800)  #set this to 1/3 of the available memory
  127.  
  128.  
  129.  
  130. /*
  131.  
  132. LoadPlugin("plugins/Deflicker.dll")
  133. Loadplugin("plugins/Depan.dll")
  134. LoadPlugin("plugins/DepanEstimate.dll")
  135. Loadplugin("plugins/removegrain.dll")
  136. LoadPlugin("plugins/removedirt.dll")
  137. LoadPlugin("plugins/MVTools.dll")
  138. LoadPlugin("plugins/MVTools2.dll")
  139. Loadplugin("plugins/warpsharp.dll")
  140. loadplugin("plugins/autolevels_06.dll")
  141. LoadPlugin("plugins/Motion_06Dec05B.dll")
  142. Import("plugins/03_RemoveDirtMC.avs")
  143.  
  144. */
  145.  
  146.  
  147. source= FFVideoSource(film).assumefps(play_speed).trim(trim_begin,0).converttoYV12()
  148. trimming= framecount(source)-trim_end
  149. source1= trim(source,0,trimming)
  150.  
  151.  
  152.  
  153.  
  154. #STABILIZING/CROPPING
  155. #..........................................................................................................................................
  156.  
  157. stab_reference= source1.crop(20,20,-20,-20).colorYUV(autogain=true).crop(est_left,est_top,-est_right,-est_bottom)
  158.  
  159. mdata=DePanEstimate(stab_reference,trust=trust_value,dxmax=maxstabH,dymax=maxstabV)
  160. stab=DePanStabilize(source1,data=mdata,cutoff=cutoff_value,dxmax=maxstabH,dymax=maxstabV,method=0,mirror=15).deflicker()
  161. stab2= stab.crop(CLeft,CTop,-CRight,-CBottom)
  162. stab3=DePanStabilize(source1,data=mdata,cutoff=cutoff_value,dxmax=maxstabH,dymax=maxstabV,method=0,info=true)
  163.  
  164.  
  165. WS= width(stab)
  166. HS= height(stab)
  167. stab4= stab3.addborders(10,10,10,10,$B1B1B1).Lanczos4Resize(WS,HS)
  168. stab5= Lanczos4Resize(stab2,W,H).sharpen(0.5)
  169.  
  170.  
  171. #UNSHARPMASK AUTO_PARAMETERS
  172. #-------------------------------------------------------------------------------------------------------------------------------------------
  173.  
  174. USM_sharp_ness1 = USM_sharp_ness
  175. USM_sharp_ness2 = USM_sharp_ness+(USM_sharp_ness/2)
  176. USM_sharp_ness3 = USM_sharp_ness*2
  177.  
  178. USM_radi_us1 = USM_radi_us
  179. USM_radi_us2 = USM_radi_us-1
  180. USM_radi_us3 = USM_radi_us2-1
  181.  
  182.  
  183. #CLEANING/PRESHARPENING/RESIZING
  184. #...........................................................................................................................................
  185.  
  186.  
  187. noise_baseclip= stab2.levels(0,gamma,255,0,255).tweak(sat=saturation)
  188.  
  189.  
  190.  
  191.  
  192. cleaned= RemoveDirtMC(noise_baseclip,dirt_strenght).unsharpmask(USM_sharp_ness1,USM_radi_us1,0).unsharpmask(USM_sharp_ness2,USM_radi_us2,0).Lanczos4Resize(W,H)
  193.  
  194.  
  195.  
  196.  
  197.  
  198. #DEGRAINING/SHARPENING
  199. #.................................................................................................................................................
  200.  
  201.  
  202.  
  203. vectors= cleaned.MAnalyse(refframes=denoising_frames, pel=2, blksize=block_size, blksizev= block_size_v, overlap=block_over, idx=1)
  204. denoised= cleaned.MDegrain(vectors, thSAD=denoising_strenght, SadMode=1, idx=2).unsharpmask(USM_sharp_ness3,USM_radi_us3,0).sharpen(last_sharp)
  205.  
  206.  
  207. #RESULT1: AUTOLEVELS,AUTOWHITE
  208. #.................................................................................................................................................
  209. result1= denoised.coloryuv(autowhite=true).converttoRGB24().autolevels(output_low= autolev_low, output_high= autolev_high).converttoYV12().BlendFPS(final_framerate, frame_blend).blur(last_blur).addborders(bord_left, bord_top, bord_right, bord_bot)
  210.  
  211. #RESULT2: MANUAL LEVELS, AUTOWHITE
  212. #.................................................................................................................................................
  213. result2= denoised.levels(black_level,1.0,white_level,0,255).coloryuv(autowhite=true).BlendFPS(final_framerate, frame_blend).blur(last_blur).addborders(bord_left, bord_top, bord_right, bord_bot)
  214.  
  215.  
  216. #RESULT3: AUTOLEVELS, MANUAL COLOR CORRECTIONS
  217. #.................................................................................................................................................
  218. result3= denoised.coloryuv(off_U=blue,off_V=red).converttoRGB24().autolevels(output_low= autolev_low, output_high= autolev_high).converttoYV12().BlendFPS(final_framerate, frame_blend).blur(last_blur).addborders(bord_left, bord_top, bord_right, bord_bot)
  219.  
  220. #RESULT4: MANUAL LEVELS, MANUAL COLOR CORRECTIONS
  221. #..................................................................................................................................................
  222. result4= denoised.coloryuv(off_U=blue,off_V=red).levels(black_level,1.0,white_level,0,255).BlendFPS(final_framerate, frame_blend).blur(last_blur).addborders(bord_left, bord_top, bord_right, bord_bot)
  223.  
  224. #RESULT5: SPECIAL SERVICE CLIP FOR RESULT S5
  225. #..................................................................................................................................................
  226. result5= overlay(source1,greyscale(stab_reference),x=est_left,y=est_top).addborders(2,2,2,2,$FFFFFF).Lanczos4Resize(WS,HS)
  227.  
  228.  
  229.  
  230.  
  231. #PARAMETERS FOR THE COMPARISONS
  232. #..................................................................................................................................................
  233. W2= W+bord_left+bord_right
  234. H2= H+bord_top+bord_bot
  235.  
  236.  
  237.  
  238.  
  239.  
  240. source4=Lanczos4Resize(source1,W2,H2).changeFPS(final_framerate)
  241.  
  242.  
  243.  
  244. #COMPARISONS: ORIGINAL VS RESULTS
  245. #......................................................................................................................................................................
  246. resultS1= stackhorizontal(subtitle(source4,"original",size=28,align=2),subtitle(result1,"result1: autolevels, autowhite",size=28,align=2))
  247. resultS2= stackhorizontal(subtitle(source4,"original",size=28,align=2),subtitle(result2,"result2: autowhite, manual levels correction",size=28,align=2))
  248. resultS3= stackhorizontal(subtitle(source4,"original",size=28,align=2),subtitle(result3,"result3: autolevels, manual color correction",size=28,align=2))
  249. resultS4= stackhorizontal(subtitle(source4,"original",size=28,align=2),subtitle(result4,"result4: manual colors and levels correction",size=28,align=2))
  250. resultS5= stackhorizontal(subtitle(result3,"result3: auto levels, manual color correction",size=28,align=2),subtitle(result4,"result4: manual colors and levels correction",size=28,align=2))
  251. resultS6= stackhorizontal(subtitle(result1,"result1: autolevels, autowhite",size=28,align=2),subtitle(result2,"result2: manual levels, autowhite",size=28,align=2))
  252.  
  253. #SPECIAL COMPARISON CLIP FOR TESTING THE STABILIZER
  254. #.........................................................................................................................................................................
  255. resultS7= stackhorizontal(subtitle(result5,"baseclip for stabiliser -only the B/W clip is used",size=32,align=2),subtitle(stab4,"test stabiliser: dx=horizontal, dy=vertical",size=32,align=5)).converttoYUY2()
  256.  
  257.  
  258.  
  259. Eval(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement