Skip to content

Instantly share code, notes, and snippets.

@wiwaz
Last active October 18, 2022 12:57
Show Gist options
  • Save wiwaz/7d008d8ac409551d1ff2d99564c7edab to your computer and use it in GitHub Desktop.
Save wiwaz/7d008d8ac409551d1ff2d99564c7edab to your computer and use it in GitHub Desktop.
def MLMDegrain(
clip: vs.VideoNode,
resolutions: tuple | list,
degrain_args: dict | list = {},
) -> vs.VideoNode:
if type(resolutions) is tuple:
resolutions = [resolutions]
if type(degrain_args) is dict:
degrain_args = [degrain_args] * (len(resolutions) + 1)
levels = range(len(resolutions))
scaled = []
for x in levels:
scaled.append(core.resize.Bilinear(clip, resolutions[x][0], resolutions[x][1]))
scaled.append(clip)
diff = []
for x in levels:
diff.append(
core.std.MakeDiff(
core.resize.Bilinear(
scaled[x], scaled[x + 1].width, scaled[x + 1].height
),
scaled[x + 1],
)
)
den = [MCDegrain(scaled[0], **degrain_args[0])]
for x in levels:
den.append(
MCDegrain(
diff[x],
prefilter=core.resize.Bilinear(den[0], diff[x].width, diff[x].height),
**degrain_args[x + 1],
)
)
den[x + 1] = core.std.MakeDiff(
core.resize.Bilinear(den[x], den[x + 1].width, den[x + 1].height),
den[x + 1],
)
return den[-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment