Registered User
Join Date: Dec 2005
Location: Germany
Posts: 1,795
|
So here is my first (alpha) port. It uses masktools2 from avisynth for now because I don't know all the vapoursynth "masktools" equivalents.
(I used an older masktools x64 build from here https://github.com/tp7/masktools/releases
the Avisynth+ masktools by pinterf https://github.com/pinterf/masktools/releases is chrashing immediately:
Plugin /coreplugins/AvsCompat.dll tried to register 'mt_invert' more than once.
Plugin /coreplugins/AvsCompat.dll tried to register 'mt_invert' more than once.
)
@Myrsloik Are Avisynth+ plugins supported by vapoursynth?
This gives me different results in avs and vp:
Code:
orig.Unsharpmask(300, 4, 0)
sharp = last
mt_merge(sharp, orig, orig)
VS
Code:
orig = UnsharpMask(clip, 300, 4, 0)
sharp = clip
clip = core.std.MaskedMerge(sharp, orig, orig) [OR clip = core.avs.mt_merge(sharp, orig, orig)]
The problem is the merge function. It seems like in doesn't merge it in vapoursynth like in avisynth.
http://i.imgur.com/jRRPPVD.jpg
I also noticed something... there is detailmaskpre0, detailmaskpre1, detailmaskpre2 in mftoon, but it is not used anywhere in the script later and slows down by a factor of 10
When I uncomment the lines -> 13fps vs 150fps, same output. That's why the dboost parameter did nothing for me xD
Would this be a correct translation to vapoursynth?
Code:
mt_merge(sharp, orig, orig) -> clip = core.std.MaskedMerge(sharp, orig, orig)
dark.BicubicResize(ssw2, ssh2, 0, 0.75) ->dark.resize.Bicubic(ssw2, ssh2, filter_param_a = 0, filter_param_b = 0.75)
darkmerged = dark.avs.MergeChroma(orig) -> darkmerged = core.std.ShufflePlanes(clips=[dark, orig], planes=[0, 1, 2], colorfamily=clip.format.color_family)
This is my port so far (I tried to stay close to avisynth code, for now at least):
Code:
def mftoon2(clip, twidth=None, theight=None, ssw=4, ssh=4, xstren=255, xthresh=255, cwarp=True,
sharpen=True, strength=255, wdepth=16, wblur=1, wthresh=128, drange=64, dboost=1.0,
dlimit=30, debug=False, doutput=None, dclip=None, show=False, scolor="$FF00FF"):
#NOTE
#awarpsharp1 wthresh of 0.5 == 128 in awarpsharp2
#http://avisynth.nl/index.php/AWarpsharp2/aWarpSharp
cwarp2 = 0
if(cwarp):
cwarp2 = 1
ssw = 4 # supersample factor horizontally, 0-inf
ssh = 4 # supersample factor vertically, 0-inf
twidth = clip.width
theight = clip.height
ssw2 = twidth * ssw
ssh2 = theight * ssh
orig = UnsharpMask(clip, 300, 4, 0)
sharp = clip
clip = core.std.MaskedMerge(sharp, orig, orig)
#clip = core.avs.mt_merge(sharp, orig, orig)
sharp1 = clip
clip = core.std.MaskedMerge(sharp1, orig, orig)
#clip = core.avs.mt_merge(sharp1, orig, orig)
sharp2 = clip
graymask = orig.avs.mt_invert(U=-128, Y=-128) #NOT USED??
#graymask = core.std.ShufflePlanes(clip, 0, colorfamily=vs.GRAY)
#return graymask
#AVS
# Tweak( clip , float hue, float sat, float bright, float cont,
# bool coring, bool sse, float startHue, float endHue,
# float maxSat, float minSat, float interp, bool dither ] )
# Levels(clip input,
# int input_low, float gamma, int input_high,
# int output_low, int output_high
# [, bool coring , bool dither ] )
#
# std.Levels(clip clip[, float[] min_in, float[] max_in, float[] gamma=1.0, float[] min_out, float[] max_out, int[] planes=[0, 1, 2]])
#detailmaskpre0 = NOT USED??
d0 = orig.avs.mt_edge(thY1 = 3, thY2 = 255, thC1 = 255, thC2 = 255, mode = "cartoon", Y=3, V=1, U=1)
d0 = adjust.Tweak(d0, hue=0.0, sat=1.0, bright=drange, cont=1.0)
d0 = core.std.Levels(d0, min_in=60, gamma=dboost, max_in=255, min_out=0, max_out=255)
d0 = core.std.Levels(d0, min_in=0, gamma=dboost, max_in=dlimit, min_out=255, max_out=0)
detailmaskpre0 = d0.avs.mt_inflate(U=-128, V=-128).avs.mt_deflate().avs.mt_deflate().avs.mt_deflate()
d1 = orig.avs.mt_edge(thY1 = 3, thY2 = 255, thC1 = 255, thC2 = 255, mode = "roberts", Y=3, V=1, U=1)
d1 = adjust.Tweak(d1, hue=0.0, sat=1.0, bright=drange, cont=1.0)
d1 = core.std.Levels(d1, min_in=60, gamma=dboost, max_in=255, min_out=0, max_out=255)
d1 = core.std.Levels(d1, min_in=0, gamma=dboost, max_in=dlimit, min_out=255, max_out=0)
detailmaskpre1 = d1.avs.mt_inflate(U=-128, V=-128)
#Convolution(matrix=[1, 2, 1, 2, 4, 2, 1, 2, 1]) = blur(1)
#detailmaskpre2 = clip.avs.mt_lut(detailmaskpre1, "x x * x * x * 256 / 256 / 256 /").std.Convolution(matrix=[1, 2, 1, 2, 4, 2, 1, 2, 1]).std.Levels(d1, min_in=60, gamma=dboost, max_in=255, min_out=0, max_out=255)
clip = clip.avs.mt_deflate()
#clip = core.std.ShufflePlanes(clip, 0, colorfamily=vs.GRAY)
detailmask = clip
white = orig.avs.mt_binarize(Y=-255,U=-128,V=-128)
linemask1 = core.avs.mt_merge(white, detailmask, orig.avs.mt_invert()).avs.mt_invert()
linemask = core.std.Levels(linemask1, min_in=0, gamma=1.0, max_in=255, min_out=0, max_out=strength)
if(strength == 255):
linemask = linemask1
sharp3 = sharp2
dark = core.avs.mt_merge(orig, sharp3, linemask, Y=3, U=1, V=1)
darkmerged = core.std.ShufflePlanes(clips=[dark,orig], planes=[0, 1, 2], colorfamily=clip.format.color_family)#dark.avs.MergeChroma(orig)
finaldark = darkmerged
semifinal = orig.resize.Bicubic(twidth, theight, filter_param_a = 0, filter_param_b = 0.75) #, b=0, c=0.75 ??
final = dark.resize.Bicubic(ssw2, ssh2, filter_param_a = 0, filter_param_b = 0.75)
final = Xsharpen(final, xstren, xthresh)
final = final.resize.Bicubic(twidth, theight, filter_param_a = 0, filter_param_b = 0.75)
final = core.std.ShufflePlanes(clips=[final,semifinal], planes=[0, 1, 2], colorfamily=clip.format.color_family)#avs.MergeChroma(semifinal)
final = final.warp.AWarpSharp2(chroma=cwarp2, depth=wdepth, blur=wblur, thresh=wthresh)
return final
Last edited by ChaosKing; 8th April 2017 at 14:36.
|