Guest User

Untitled

a guest
Nov 7th, 2024
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.32 KB | None | 0 0
  1. import vapoursynth as vs
  2. import math
  3.  
  4. fmtc_args = dict(fulls=True, fulld=True)
  5. msuper_args = dict(hpad=0, vpad=0, sharp=2, levels=0)
  6. manalyze_args = dict(search=3, truemotion=False, trymany=True, levels=0, badrange=-24, divide=0, dct=0)
  7. mrecalculate_args = dict(truemotion=False, search=3, smooth=1, divide=0, dct=0)
  8. mdegrain_args = dict(thscd1=16711680.0, thscd2=255.0)
  9. nnedi_args = dict(field=1, dh=True, nns=4, qual=2, etype=1, nsize=0)
  10. dfttest_args = dict(smode=0, sosize=0, tbsize=1, tosize=0, tmode=0)
  11.  
  12. class get_core:
  13. def __init__(self):
  14. self.core = vs.get_core()
  15. self.MSuper = self.core.mvsf.Super
  16. self.MAnalyze = self.core.mvsf.Analyze
  17. self.MRecalculate = self.core.mvsf.Recalculate
  18. self.MDegrain = self.core.mvsf.Degrain
  19. self.RGB2OPP = self.core.bm3d.RGB2OPP
  20. self.OPP2RGB = self.core.bm3d.OPP2RGB
  21. self.BMBasic = self.core.bm3d.VBasic
  22. self.BMFinal = self.core.bm3d.VFinal
  23. self.Aggregate = self.core.bm3d.VAggregate
  24. self.DFTTest = self.core.dfttest.DFTTest
  25. self.KNLMeansCL = self.core.knlm.KNLMeansCL
  26. self.NNEDI = self.core.nnedi3.nnedi3
  27. self.Resample = self.core.fmtc.resample
  28. self.Expr = self.core.std.Expr
  29. self.MakeDiff = self.core.std.MakeDiff
  30. self.MergeDiff = self.core.std.MergeDiff
  31. self.Crop = self.core.std.CropRel
  32. self.CropAbs = self.core.std.CropAbs
  33. self.Transpose = self.core.std.Transpose
  34. self.BlankClip = self.core.std.BlankClip
  35. self.AddBorders = self.core.std.AddBorders
  36. self.StackHorizontal = self.core.std.StackHorizontal
  37. self.StackVertical = self.core.std.StackVertical
  38. self.MaskedMerge = self.core.std.MaskedMerge
  39. self.ShufflePlanes = self.core.std.ShufflePlanes
  40. self.SetFieldBased = self.core.std.SetFieldBased
  41.  
  42. def FreqMerge(self, low, hi, sbsize, slocation):
  43. hif = self.MakeDiff(hi, self.DFTTest(hi, sbsize=sbsize, slocation=slocation, **dfttest_args))
  44. clip = self.MergeDiff(self.DFTTest(low, sbsize=sbsize, slocation=slocation, **dfttest_args), hif)
  45. return clip
  46.  
  47. def Pad(self, src, left, right, top, bottom):
  48. w = src.width
  49. h = src.height
  50. clip = self.Resample(src, w+left+right, h+top+bottom, -left, -top, w+left+right, h+top+bottom, kernel="point", **fmtc_args)
  51. return clip
  52.  
  53. def NLMeans(self, src, d, a, s, h, rclip, color):
  54. def duplicate(src):
  55. if d > 0:
  56. blank = self.Expr(src[0], "0.0") * d
  57. clip = blank + src + blank
  58. else:
  59. clip = src
  60. return clip
  61. pad = self.AddBorders(src, a+s, a+s, a+s, a+s)
  62. pad = duplicate(pad)
  63. if rclip is not None:
  64. rclip = self.AddBorders(rclip, a+s, a+s, a+s, a+s)
  65. rclip = duplicate(rclip)
  66. nlm = self.KNLMeansCL(pad, d=d, a=a, s=s, h=h, channels="YUV" if color else "Y", wref=1.0, rclip=rclip)
  67. clip = self.Crop(nlm, a+s, a+s, a+s, a+s)
  68. return clip[d:clip.num_frames - d]
  69.  
  70. def ThrMerge(self, flt, src, ref=None, thr=0.0009765625, elast=None):
  71. ref = src if ref is None else ref
  72. elast = thr / 2 if elast is None else elast
  73. BExp = ["x {thr} {elast} + z - 2 {elast} * / * y {elast} z + {thr} - 2 {elast} * / * +".format(thr=thr, elast=elast)]
  74. BDif = self.Expr(src, "0.0")
  75. PDif = self.Expr([flt, src], "x y - 0.0 max")
  76. PRef = self.Expr([flt, ref], "x y - 0.0 max")
  77. PBLD = self.Expr([PDif, BDif, PRef], BExp)
  78. NDif = self.Expr([flt, src], "y x - 0.0 max")
  79. NRef = self.Expr([flt, ref], "y x - 0.0 max")
  80. NBLD = self.Expr([NDif, BDif, NRef], BExp)
  81. BLDD = self.MakeDiff(PBLD, NBLD)
  82. BLD = self.MergeDiff(src, BLDD)
  83. UDN = self.Expr([flt, ref, BLD], ["x y - abs {thr} {elast} - > z x ?".format(thr=thr, elast=elast)])
  84. clip = self.Expr([flt, ref, UDN, src], ["x y - abs {thr} {elast} + < z a ?".format(thr=thr, elast=elast)])
  85. return clip
  86.  
  87. def GenBlockMask(self, src):
  88. clip = self.BlankClip(src, 24, 24, color=0.0)
  89. clip = self.AddBorders(clip, 4, 4, 4, 4, color=1.0)
  90. clip = self.StackHorizontal([clip, clip, clip, clip])
  91. clip = self.StackVertical([clip, clip, clip, clip])
  92. clip = self.Resample(clip, 32, 32, kernel="point", **fmtc_args)
  93. clip = self.Expr(clip, ["x 0.0 > 1.0 0.0 ?"])
  94. clip = self.StackHorizontal([clip, clip, clip, clip, clip, clip, clip, clip])
  95. clip = self.StackVertical([clip, clip, clip, clip, clip, clip])
  96. clip = self.StackHorizontal([clip, clip, clip, clip, clip, clip])
  97. clip = self.StackVertical([clip, clip, clip, clip, clip])
  98. clip = self.StackHorizontal([clip, clip, clip, clip, clip, clip])
  99. clip = self.StackVertical([clip, clip, clip, clip, clip])
  100. clip = self.CropAbs(clip, src.width, src.height, 0, 0)
  101. return clip
  102.  
  103. class internal:
  104. def super(core, src, pel):
  105. src = core.Pad(src, 128, 128, 128, 128)
  106. clip = core.Transpose(core.NNEDI(core.Transpose(core.NNEDI(src, **nnedi_args)), **nnedi_args))
  107. if pel == 4:
  108. clip = core.Transpose(core.NNEDI(core.Transpose(core.NNEDI(clip, **nnedi_args)), **nnedi_args))
  109. return clip
  110.  
  111. def basic(core, src, super, radius, pel, sad, short_time, color):
  112. plane = 4 if color else 0
  113. src = core.Pad(src, 128, 128, 128, 128)
  114. supersoft = core.MSuper(src, pelclip=super, rfilter=4, pel=pel, chroma=color, **msuper_args)
  115. supersharp = core.MSuper(src, pelclip=super, rfilter=2, pel=pel, chroma=color, **msuper_args)
  116. if short_time:
  117. constant = 0.0001989762736579584832432989326
  118. me_sad = [constant * math.pow(sad, 2.0) * math.log(1.0 + 1.0 / (constant * sad))]
  119. me_sad += [sad]
  120. vmulti = core.MAnalyze(supersoft, radius=radius, chroma=color, overlap=4, blksize=8, **manalyze_args)
  121. vmulti = core.MRecalculate(supersoft, vmulti, chroma=color, overlap=2, blksize=4, thsad=me_sad[0], **mrecalculate_args)
  122. vmulti = core.MRecalculate(supersoft, vmulti, chroma=color, overlap=1, blksize=2, thsad=me_sad[1], **mrecalculate_args)
  123. else:
  124. constant = 0.0000139144247313257680589719533
  125. me_sad = constant * math.pow(sad, 2.0) * math.log(1.0 + 1.0 / (constant * sad))
  126. vmulti = core.MAnalyze(supersoft, radius=radius, chroma=color, overlap=64, blksize=128, **manalyze_args)
  127. vmulti = core.MRecalculate(supersoft, vmulti, chroma=color, overlap=32, blksize=64, thsad=me_sad, **mrecalculate_args)
  128. vmulti = core.MRecalculate(supersoft, vmulti, chroma=color, overlap=16, blksize=32, thsad=me_sad, **mrecalculate_args)
  129. vmulti = core.MRecalculate(supersoft, vmulti, chroma=color, overlap=8, blksize=16, thsad=me_sad, **mrecalculate_args)
  130. vmulti = core.MRecalculate(supersoft, vmulti, chroma=color, overlap=4, blksize=8, thsad=me_sad, **mrecalculate_args)
  131. vmulti = core.MRecalculate(supersoft, vmulti, chroma=color, overlap=2, blksize=4, thsad=me_sad, **mrecalculate_args)
  132. clip = core.MDegrain(src, supersharp, vmulti, thsad=sad, plane=plane, **mdegrain_args)
  133. clip = core.Crop(clip, 128, 128, 128, 128)
  134. return clip
  135.  
  136. def deringing(core, src, ref, radius, h, sigma, \
  137. mse, hard_thr, block_size, block_step, group_size, bm_range, bm_step, ps_num, ps_range, ps_step, \
  138. lowpass, color, matrix):
  139. c1 = 0.1134141984932795312503328847998
  140. c2 = 2.8623043756241389436528021745239
  141. strength = [h]
  142. strength += [h * math.pow(c1 * h, c2) * math.log(1.0 + 1.0 / math.pow(c1 * h, c2))]
  143. strength += [None]
  144. def loop(flt, init, src, n):
  145. strength[2] = n * strength[0] / 4 + strength[1] * (1 - n / 4)
  146. window = int(32 / math.pow(2, n))
  147. flt = init if n == 4 else flt
  148. dif = core.MakeDiff(src, flt)
  149. dif = core.NLMeans(dif, 0, window, 1, strength[2], flt, color)
  150. fnl = core.MergeDiff(flt, dif)
  151. n -= 1
  152. return fnl if n == -1 else loop(fnl, init, src, n)
  153. ref = core.FreqMerge(src, ref, block_size // 2 * 2 + 1, lowpass)
  154. dif = core.MakeDiff(src, ref)
  155. dif = core.BMBasic(dif, ref, radius=radius, th_mse=mse[0], hard_thr=hard_thr, sigma=sigma, \
  156. block_size=block_size, block_step=block_step, group_size=group_size, bm_range=bm_range, bm_step=bm_step, \
  157. ps_num=ps_num, ps_range=ps_range, ps_step=ps_step, matrix=matrix)
  158. dif = core.Aggregate(dif, radius, 1)
  159. ref = core.MergeDiff(ref, dif)
  160. refined = loop(None, ref, src, 4)
  161. bm3d = core.BMFinal(refined, ref, radius=radius, th_mse=mse[1], sigma=sigma, \
  162. block_size=block_size, block_step=block_step, group_size=group_size, bm_range=bm_range, bm_step=bm_step, \
  163. ps_num=ps_num, ps_range=ps_range, ps_step=ps_step, matrix=matrix)
  164. bm3d = core.Aggregate(bm3d, radius, 1)
  165. bm3d = core.FreqMerge(refined, bm3d, block_size // 2 * 2 + 1, lowpass)
  166. clip = loop(None, bm3d, refined, 4)
  167. return clip
  168.  
  169. def destaircase(core, src, ref, radius, sigma, \
  170. mse, hard_thr, block_size, block_step, group_size, bm_range, bm_step, ps_num, ps_range, ps_step, \
  171. thr, elast, lowpass, matrix):
  172. mask = core.GenBlockMask(core.ShufflePlanes(src, 0, vs.GRAY))
  173. ref = core.FreqMerge(src, ref, block_size // 2 * 2 + 1, lowpass)
  174. ref = core.ThrMerge(src, ref, thr=thr, elast=elast)
  175. dif = core.MakeDiff(src, ref)
  176. dif = core.BMBasic(dif, ref, radius=radius, th_mse=mse[0], hard_thr=hard_thr, sigma=sigma, \
  177. block_size=block_size, block_step=block_step, group_size=group_size, bm_range=bm_range, bm_step=bm_step, \
  178. ps_num=ps_num, ps_range=ps_range, ps_step=ps_step, matrix=matrix)
  179. dif = core.Aggregate(dif, radius, 1)
  180. ref = core.MergeDiff(ref, dif)
  181. dif = core.MakeDiff(src, ref)
  182. dif = core.BMFinal(dif, ref, radius=radius, th_mse=mse[1], sigma=sigma, \
  183. block_size=block_size, block_step=block_step, group_size=group_size, bm_range=bm_range, bm_step=bm_step, \
  184. ps_num=ps_num, ps_range=ps_range, ps_step=ps_step, matrix=matrix)
  185. dif = core.Aggregate(dif, radius, 1)
  186. ref = core.MergeDiff(ref, dif)
  187. clip = core.MaskedMerge(src, ref, mask, first_plane=True)
  188. return clip
  189.  
  190. def deblocking(core, src, ref, radius, h, sigma, \
  191. mse, hard_thr, block_size, block_step, group_size, bm_range, bm_step, ps_num, ps_range, ps_step, \
  192. lowpass, color, matrix):
  193. mask = core.GenBlockMask(core.ShufflePlanes(src, 0, vs.GRAY))
  194. cleansed = core.NLMeans(ref, radius, block_size, math.ceil(block_size / 2), h, ref, color)
  195. dif = core.MakeDiff(ref, cleansed)
  196. dif = core.BMBasic(dif, cleansed, radius=radius, th_mse=mse[0], hard_thr=hard_thr, sigma=sigma, \
  197. block_size=block_size, block_step=block_step, group_size=group_size, bm_range=bm_range, bm_step=bm_step, \
  198. ps_num=ps_num, ps_range=ps_range, ps_step=ps_step, matrix=matrix)
  199. dif = core.Aggregate(dif, radius, 1)
  200. cleansed = core.MergeDiff(cleansed, dif)
  201. dif = core.MakeDiff(ref, cleansed)
  202. dif = core.BMFinal(dif, cleansed, radius=radius, th_mse=mse[1], sigma=sigma, \
  203. block_size=block_size, block_step=block_step, group_size=group_size, bm_range=bm_range, bm_step=bm_step, \
  204. ps_num=ps_num, ps_range=ps_range, ps_step=ps_step, matrix=matrix)
  205. dif = core.Aggregate(dif, radius, 1)
  206. cleansed = core.MergeDiff(cleansed, dif)
  207. ref = core.FreqMerge(cleansed, ref, block_size // 2 * 2 + 1, lowpass)
  208. src = core.FreqMerge(cleansed, src, block_size // 2 * 2 + 1, lowpass)
  209. clip = core.MaskedMerge(src, ref, mask, first_plane=True)
  210. return clip
  211.  
  212. def Super(src, pel=4):
  213. if not isinstance(src, vs.VideoNode):
  214. raise TypeError("Oyster.Super: src has to be a video clip!")
  215. elif src.format.sample_type != vs.FLOAT or src.format.bits_per_sample < 32:
  216. raise TypeError("Oyster.Super: the sample type of src has to be single precision!")
  217. elif src.format.subsampling_w > 0 or src.format.subsampling_h > 0:
  218. raise RuntimeError("Oyster.Super: subsampled stuff not supported!")
  219. if not isinstance(pel, int):
  220. raise TypeError("Oyster.Super: pel has to be an integer!")
  221. elif pel != 2 and pel != 4:
  222. raise RuntimeError("Oyster.Super: pel has to be 2 or 4!")
  223. core = get_core()
  224. src = core.SetFieldBased(src, 0)
  225. colorspace = src.format.color_family
  226. if colorspace == vs.RGB:
  227. src = core.RGB2OPP(src, 1)
  228. clip = internal.super(core, src, pel)
  229. del core
  230. return clip
  231.  
  232. def Basic(src, super=None, radius=6, pel=4, sad=2000.0, short_time=False):
  233. if not isinstance(src, vs.VideoNode):
  234. raise TypeError("Oyster.Basic: src has to be a video clip!")
  235. elif src.format.sample_type != vs.FLOAT or src.format.bits_per_sample < 32:
  236. raise TypeError("Oyster.Basic: the sample type of src has to be single precision!")
  237. elif src.format.subsampling_w > 0 or src.format.subsampling_h > 0:
  238. raise RuntimeError("Oyster.Basic: subsampled stuff not supported!")
  239. if not isinstance(super, vs.VideoNode) and super is not None:
  240. raise TypeError("Oyster.Basic: super has to be a video clip or None!")
  241. elif super is not None:
  242. if super.format.sample_type != vs.FLOAT or super.format.bits_per_sample < 32 or super.format.subsampling_w > 0 or super.format.subsampling_h > 0:
  243. raise RuntimeError("Oyster.Basic: corrupted super clip!")
  244. if not isinstance(radius, int):
  245. raise TypeError("Oyster.Basic: radius has to be an integer!")
  246. elif radius < 1:
  247. raise RuntimeError("Oyster.Basic: radius has to be greater than 0!")
  248. if not isinstance(pel, int):
  249. raise TypeError("Oyster.Basic: pel has to be an integer!")
  250. elif pel != 1 and pel != 2 and pel != 4:
  251. raise RuntimeError("Oyster.Basic: pel has to be 1, 2 or 4!")
  252. if not isinstance(sad, float) and not isinstance(sad, int):
  253. raise TypeError("Oyster.Basic: sad has to be a real number!")
  254. elif sad <= 0.0:
  255. raise RuntimeError("Oyster.Basic: sad has to be greater than 0!")
  256. if not isinstance(short_time, bool):
  257. raise TypeError("Oyster.Basic: short_time has to be boolean!")
  258. core = get_core()
  259. color = True
  260. rgb = False
  261. colorspace = src.format.color_family
  262. if colorspace == vs.RGB:
  263. src = core.RGB2OPP(src, 1)
  264. rgb = True
  265. if colorspace == vs.GRAY:
  266. color = False
  267. src = core.SetFieldBased(src, 0)
  268. super = core.SetFieldBased(super, 0) if super is not None else None
  269. clip = internal.basic(core, src, super, radius, pel, sad, short_time, color)
  270. clip = core.OPP2RGB(clip, 1) if rgb else clip
  271. del core
  272. return clip
  273.  
  274. def Deringing(src, ref, radius=6, h=6.4, sigma=16.0, \
  275. mse=[None, None], hard_thr=3.2, block_size=8, block_step=1, group_size=32, bm_range=24, bm_step=1, ps_num=2, ps_range=8, ps_step=1, \
  276. lowpass=None):
  277. if not isinstance(src, vs.VideoNode):
  278. raise TypeError("Oyster.Deringing: src has to be a video clip!")
  279. elif src.format.sample_type != vs.FLOAT or src.format.bits_per_sample < 32:
  280. raise TypeError("Oyster.Deringing: the sample type of src has to be single precision!")
  281. elif src.format.subsampling_w > 0 or src.format.subsampling_h > 0:
  282. raise RuntimeError("Oyster.Deringing: subsampled stuff not supported!")
  283. if not isinstance(ref, vs.VideoNode):
  284. raise TypeError("Oyster.Deringing: ref has to be a video clip!")
  285. elif ref.format.sample_type != vs.FLOAT or ref.format.bits_per_sample < 32:
  286. raise TypeError("Oyster.Deringing: the sample type of ref has to be single precision!")
  287. elif ref.format.subsampling_w > 0 or ref.format.subsampling_h > 0:
  288. raise RuntimeError("Oyster.Deringing: subsampled stuff not supported!")
  289. if not isinstance(radius, int):
  290. raise TypeError("Oyster.Deringing: radius has to be an integer!")
  291. elif radius < 1:
  292. raise RuntimeError("Oyster.Deringing: radius has to be greater than 0!")
  293. if not isinstance(h, float) and not isinstance(h, int):
  294. raise TypeError("Oyster.Deringing: h has to be a real number!")
  295. elif h <= 0:
  296. raise RuntimeError("Oyster.Deringing: h has to be greater than 0!")
  297. if not isinstance(mse, list):
  298. raise TypeError("Oyster.Deringing: mse parameter has to be an array!")
  299. elif len(mse) != 2:
  300. raise RuntimeError("Oyster.Deringing: mse parameter has to contain 2 elements exactly!")
  301. for i in range(2):
  302. if not isinstance(mse[i], float) and not isinstance(mse[i], int) and mse[i] is not None:
  303. raise TypeError("Oyster.Deringing: elements in mse must be real numbers or None!")
  304. if not isinstance(lowpass, list) and lowpass is not None:
  305. raise TypeError("Oyster.Deringing: lowpass has to be a list or None!")
  306. core = get_core()
  307. rgb = False
  308. color = True
  309. mse[0] = sigma * 160.0 + 1200.0 if mse[0] is None else mse[0]
  310. mse[1] = sigma * 120.0 + 800.0 if mse[1] is None else mse[1]
  311. lowpass = [0.0,sigma, 0.48,1024.0, 1.0,1024.0] if lowpass is None else lowpass
  312. matrix = None
  313. colorspace = src.format.color_family
  314. if colorspace == vs.RGB:
  315. rgb = True
  316. matrix = 100
  317. src = core.RGB2OPP(src, 1)
  318. ref = core.RGB2OPP(ref, 1)
  319. if colorspace == vs.GRAY:
  320. color = False
  321. src = core.SetFieldBased(src, 0)
  322. ref = core.SetFieldBased(ref, 0)
  323. clip = internal.deringing(core, src, ref, radius, h, sigma, \
  324. mse, hard_thr, block_size, block_step, group_size, bm_range, bm_step, ps_num, ps_range, ps_step, \
  325. lowpass, color, matrix)
  326. clip = core.OPP2RGB(clip, 1) if rgb else clip
  327. del core
  328. return clip
  329.  
  330. def Destaircase(src, ref, radius=6, sigma=16.0, \
  331. mse=[None, None], hard_thr=3.2, block_size=8, block_step=1, group_size=32, bm_range=24, bm_step=1, ps_num=2, ps_range=8, ps_step=1, \
  332. thr=0.03125, elast=0.015625, lowpass=None):
  333. if not isinstance(src, vs.VideoNode):
  334. raise TypeError("Oyster.Destaircase: src has to be a video clip!")
  335. elif src.format.sample_type != vs.FLOAT or src.format.bits_per_sample < 32:
  336. raise TypeError("Oyster.Destaircase: the sample type of src has to be single precision!")
  337. elif src.format.subsampling_w > 0 or src.format.subsampling_h > 0:
  338. raise RuntimeError("Oyster.Destaircase: subsampled stuff not supported!")
  339. if not isinstance(ref, vs.VideoNode):
  340. raise TypeError("Oyster.Destaircase: ref has to be a video clip!")
  341. elif ref.format.sample_type != vs.FLOAT or ref.format.bits_per_sample < 32:
  342. raise TypeError("Oyster.Destaircase: the sample type of ref has to be single precision!")
  343. elif ref.format.subsampling_w > 0 or ref.format.subsampling_h > 0:
  344. raise RuntimeError("Oyster.Destaircase: subsampled stuff not supported!")
  345. if not isinstance(radius, int):
  346. raise TypeError("Oyster.Destaircase: radius has to be an integer!")
  347. elif radius < 1:
  348. raise RuntimeError("Oyster.Destaircase: radius has to be greater than 0!")
  349. if not isinstance(mse, list):
  350. raise TypeError("Oyster.Destaircase: mse parameter has to be an array!")
  351. elif len(mse) != 2:
  352. raise RuntimeError("Oyster.Destaircase: mse parameter has to contain 2 elements exactly!")
  353. for i in range(2):
  354. if not isinstance(mse[i], float) and not isinstance(mse[i], int) and mse[i] is not None:
  355. raise TypeError("Oyster.Destaircase: elements in mse must be real numbers or None!")
  356. if not isinstance(thr, float) and not isinstance(thr, int):
  357. raise TypeError("Oyster.Destaircase: thr has to be a real number!")
  358. elif thr < 0 or thr > 1:
  359. raise RuntimeError("Oyster.Destaircase: thr has to fall in [0, 1]!")
  360. if not isinstance(elast, float) and not isinstance(elast, int):
  361. raise TypeError("Oyster.Destaircase: elast has to be a real number!")
  362. elif elast < 0 or elast > thr:
  363. raise RuntimeError("Oyster.Destaircase: elast has to fall in [0, thr]!")
  364. if not isinstance(lowpass, list) and lowpass is not None:
  365. raise TypeError("Oyster.Destaircase: lowpass has to be a list or None!")
  366. core = get_core()
  367. rgb = False
  368. mse[0] = sigma * 160.0 + 1200.0 if mse[0] is None else mse[0]
  369. mse[1] = sigma * 120.0 + 800.0 if mse[1] is None else mse[1]
  370. lowpass = [0.0,sigma, 0.48,1024.0, 1.0,1024.0] if lowpass is None else lowpass
  371. matrix = None
  372. colorspace = src.format.color_family
  373. if colorspace == vs.RGB:
  374. rgb = True
  375. matrix = 100
  376. src = core.RGB2OPP(src, 1)
  377. ref = core.RGB2OPP(ref, 1)
  378. src = core.SetFieldBased(src, 0)
  379. ref = core.SetFieldBased(ref, 0)
  380. clip = internal.destaircase(core, src, ref, radius, sigma, \
  381. mse, hard_thr, block_size, block_step, group_size, bm_range, bm_step, ps_num, ps_range, ps_step, \
  382. thr, elast, lowpass, matrix)
  383. clip = core.OPP2RGB(clip, 1) if rgb else clip
  384. del core
  385. return clip
  386.  
  387. def Deblocking(src, ref, radius=6, h=6.4, sigma=16.0, \
  388. mse=[None, None], hard_thr=3.2, block_size=8, block_step=1, group_size=32, bm_range=24, bm_step=1, ps_num=2, ps_range=8, ps_step=1, \
  389. lowpass=[0.0,0.0, 0.12,1024.0, 1.0,1024.0]):
  390. if not isinstance(src, vs.VideoNode):
  391. raise TypeError("Oyster.Deblocking: src has to be a video clip!")
  392. elif src.format.sample_type != vs.FLOAT or src.format.bits_per_sample < 32:
  393. raise TypeError("Oyster.Deblocking: the sample type of src has to be single precision!")
  394. elif src.format.subsampling_w > 0 or src.format.subsampling_h > 0:
  395. raise RuntimeError("Oyster.Deblocking: subsampled stuff not supported!")
  396. if not isinstance(ref, vs.VideoNode):
  397. raise TypeError("Oyster.Deblocking: ref has to be a video clip!")
  398. elif ref.format.sample_type != vs.FLOAT or ref.format.bits_per_sample < 32:
  399. raise TypeError("Oyster.Deblocking: the sample type of ref has to be single precision!")
  400. elif ref.format.subsampling_w > 0 or ref.format.subsampling_h > 0:
  401. raise RuntimeError("Oyster.Deblocking: subsampled stuff not supported!")
  402. if not isinstance(radius, int):
  403. raise TypeError("Oyster.Deblocking: radius has to be an integer!")
  404. elif radius < 1:
  405. raise RuntimeError("Oyster.Deblocking: radius has to be greater than 0!")
  406. if not isinstance(h, float) and not isinstance(h, int):
  407. raise TypeError("Oyster.Deblocking: h has to be a real number!")
  408. elif h <= 0:
  409. raise RuntimeError("Oyster.Deblocking: h has to be greater than 0!")
  410. if not isinstance(mse, list):
  411. raise TypeError("Oyster.Deblocking: mse parameter has to be an array!")
  412. elif len(mse) != 2:
  413. raise RuntimeError("Oyster.Deblocking: mse parameter has to contain 2 elements exactly!")
  414. for i in range(2):
  415. if not isinstance(mse[i], float) and not isinstance(mse[i], int) and mse[i] is not None:
  416. raise TypeError("Oyster.Deblocking: elements in mse must be real numbers or None!")
  417. if not isinstance(lowpass, list):
  418. raise TypeError("Oyster.Deblocking: lowpass has to be a list!")
  419. core = get_core()
  420. rgb = False
  421. color = True
  422. mse[0] = sigma * 160.0 + 1200.0 if mse[0] is None else mse[0]
  423. mse[1] = sigma * 120.0 + 800.0 if mse[1] is None else mse[1]
  424. matrix = None
  425. colorspace = src.format.color_family
  426. if colorspace == vs.RGB:
  427. rgb = True
  428. matrix = 100
  429. src = core.RGB2OPP(src, 1)
  430. ref = core.RGB2OPP(ref, 1)
  431. if colorspace == vs.GRAY:
  432. color = False
  433. src = core.SetFieldBased(src, 0)
  434. ref = core.SetFieldBased(ref, 0)
  435. clip = internal.deblocking(core, src, ref, radius, h, sigma, \
  436. mse, hard_thr, block_size, block_step, group_size, bm_range, bm_step, ps_num, ps_range, ps_step, \
  437. lowpass, color, matrix)
  438. clip = core.OPP2RGB(clip, 1) if rgb else clip
  439. del core
  440. return clip
  441.  
Advertisement
Add Comment
Please, Sign In to add comment