View Single Post
Old 8th April 2017, 17:05   #9  |  Link
WolframRhodium
Registered User
 
Join Date: Jan 2016
Posts: 162
linemask

There's no need to use masktools of Avisynth for such code. Most of them can be implemented under vs standard library:

Take detailmaskpre0 as an example:

Code:
detailmaskpre0 = orig.std.Convolution([0, -2, 1, 0, 1, 0, 0, 0, 0], planes=[0]).std.Expr(['x 3 < 0 x ? 255 > 255 x ?', ''])
# mt_edge(thy1 = 3, thy2 = 255, thc1 = 255, thc2 = 255, mode = "cartoon", Y=3, V=1, U=1)

detailmaskpre0 = detailmaskpre0.std.Expr(['x {} + 16 max 235 min'.format(drrange), '']) 
# Tweak(0.0, 1.0, drange, 1.0)

detailmaskpre0 = Levels(detailmaskpre0, 60, dboost, 255, 0, 255)
# Levels(60, dboost, 255, 0, 255)
# The Levels() function is at havsfunc

detailmaskpre0 = Levels(detailmaskpre0, 0, dboost, dlimit, 255, 0)
# Levels(0, dboost, dlimit, 255, 0)

detailmaskpre0 = detailmaskpre0.std.Inflate(0)
# mt_inflate(u=-128, v=-128)

detailmaskpre0 = detailmaskpre0.std.Deflate(0).std.Deflate(0).std.Deflate(0)
# mt_deflate().mt_deflate().mt_deflate()
Or in short:

Code:
detailmaskpre0 = orig.std.Convolution([0,-2,1,0,1,0,0,0,0], planes=[0])
detailmaskpre0 = detailmaskpre0.std.Expr(['x 3 < 0 x ? {} + 16 max 235 min'.format(drrange), ''])
detailmaskpre0 = Levels(Levels(detailmaskpre0, 60, dboost, 255, 0, 255), 0, dboost, dlimit, 255, 0)
detailmaskpre0 = detailmaskpre0.std.Inflate(0).std.Deflate(0).std.Deflate(0).std.Deflate(0)
remaining code is similar:
Code:
detailmaskpre1 = orig.std.Convolution([0,0,0,0,2,-1,0,-1,0], divisor=2, saturate=False, planes=[0])
detailmaskpre1 = detailmaskpre1.std.Expr(['x 3 < 0 x ? {} + 16 max 235 min'.format(drrange), '']))
detailmaskpre1 = Levels(Levels(detailmaskpre1, 60, dboost, 255, 0, 255), 0, dboost, dlimit, 255, 0)
detailmaskpre1 = detailmaskpre1.std.Inflate(0)

detailmaskpre2 = detailmaskpre1.std.Expr(['x x * dup * 16777216 /', ''])

detailmaskpre2 = detailmaskpre2.rgvs.RemoveGrain([11, 0])
# Blur(1.0)

last = sharp2.std.Deflate(0)
detailmask = last

white = orig.std.BlankClip(color=[255, 128, 128]) 
# orig.mt_binarize(Y=-255,U=-128,V=-128)

linemask1 = white.std.MaskedMerge(detailmask, orig.std.Invert(0), planes=[0]).std.Invert(0)
linemask = linemask1 if strength == 255 else Levels(linemask1, 0, 1.0, 255, 0, strength)
I don't check the code above carefully, and it only works on YUV colorspace with 8 bits per sample, for simplicity.

Last edited by WolframRhodium; 9th April 2017 at 05:50.
WolframRhodium is offline   Reply With Quote