*.mp4 guy
7th April 2008, 07:11
I have reworked an old version of lanczosplus, It now gets very similar results to the best version I have (never posted, was way to slow), but is faster, probably even fast enough to be usable. ;)
I would also like to thank everyone that contributed to the last thread, your help was indispensable.
function Lanczosplusv3( clip c, int "dx", int "dy", int "thresh", int "thresh2", float "aa2s",
\ float "sharp1", float "sharp2", float "blur1", float "blur2",
\ int "mtaps1", int "mtaps2", int "ttaps", int "ltaps", float "cstr",
\ int "depth", float "wthresh", float "wblur", float "aa", float "aa2")
{
# Requires : Masktools 2; Frfun7; fft3dfilter; aWarpsharp
# Instructions : This function performs best when enlarging by a factor of 2,
# performance degrades steadily the when enlarging by significantly larger or smaller factors
# if you have extensive aliasing in the resized image, experiment with aa values of 1.01-2.01,
# and aa2 values of 8-16, cstr varies the strength of sharpening, halo reduction and ringing
# cuncurrently, higher values add more sharpening and halo reduction, etc.
# for more exact control use the sharp1/2 and blur1/2 values
# the other valuse defaults are genearlly optimal, but feel free to experiment and report results
# note that if your source is blurry, the line detection routines will not work, and the interpolated
# picture will be blurry aswell, there is no way around this, if blurry things are treated like lines
# then artifacts will be created on gradients, and out of focus areas
# example usage : lanczosplus(1280, 720, cstr=1.5, depth=3)
dx = default(dx, c.width*2)
dy = default(dy, c.height*2)
cstr = default(cstr, 1.33)
thresh = default(thresh, 0)
thresh2 = Default(thresh2, ((thresh+1)*(thresh+1))*64/(thresh+1))
sharp1 = default(sharp1, cstr*0.125)
sharp2 = default(sharp2, cstr*1.0)
blur1 = default(blur1, cstr*0.5)
blur2 = default(blur2, cstr*0.25)
mtaps1 = default(mtaps1, 1)
mtaps2 = default(mtaps2, 1)
ttaps = default(ttaps, 3)
ltaps = default(ltaps, 7)
depth = default(depth, 3)
wthresh = default(wthresh, 0.70)
wblur = default(wblur, 1)
aa = default(aa, 0)
aa2 = default(aa2, 0)
aa2s = default(aa2s, 0)
c
s = c
fd1 = lanczosresize(c, dx, dy, taps=mtaps1)
fre1 = fd1.lanczosresize( c.width, c.height, taps=mtaps1)
fre2 = fre1.lanczosresize( c.width/2, c.height/2, taps=mtaps1).lanczosresize( c.width, c.height, taps=mtaps1)
m1 = mt_lutxy(fre1, s, "x y - abs "+string(thresh)+" - "+string(thresh2)+" *", u=0, v=0)
m2 = lanczosresize(lanczosresize(frfun7(m1, 2.01, 256, 256), c.width/2, c.height/2, taps=ttaps), \
dx, dy, taps=ttaps)
d = c#mt_merge(c, fre2, m1, u=0, v=0)
d2 = d.lanczosresize(dx, dy, taps=ttaps)
d3 = lanczosresize(lanczosresize(d, (c.width)-(width/2), (c.height)-(height/2), taps=ttaps), \
d2.width, d2.height, taps=ttaps)
d4 = mt_merge( mt_lutxy(d2, d3 , "x y - "+string(sharp1)+" * x +" , u=0, v=0), \
mt_lutxy(d2, d3 , "y x - "+string(blur1)+" * x +" , u=0, v=0), m2, u=0, v=0)
d5 = d4.lanczosresize(d.width, d.height, taps=ttaps)
e = mt_merge(d5, c, m1).lanczosresize(dx, dy, taps=ltaps)
e = aa >= 0.1 ? e.frfun7(aa, 256, 256) : e
e = aa2 >= 0.1 ? e.fft3dfilter(bw=36, bh=36, ow=18, oh=18, bt=1, sigma=aa2, plane=0, sharpen=aa2s) : e
e = e.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
e = e.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
e = e.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
e = e.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
fd12 = lanczosresize(e, e.width*(dx/c.width), e.height*(dy/c.height), taps=mtaps2)
fre12 = fd12.lanczosresize( e.width, e.height, taps=mtaps2)
fre22 = fre12.lanczosresize( e.width/2, e.height/2, taps=mtaps2).lanczosresize( e.width, e.height, taps=mtaps2)
m12 = mt_lutxy(fre12, e, "x y - abs "+string(thresh)+" - "+string(thresh2*1)+" *", u=0, v=0)
m12 = m12.lanczosresize( e.width/2, e.height/2, taps=mtaps2).lanczosresize( e.width, e.height, taps=mtaps2)
e2 = lanczosresize(lanczosresize(e, (c.width)-(width/2), (c.height)-(height/2), taps=ltaps), \
e.width, e.height, taps=ltaps)
e2 = e2.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
e2 = e2.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
e2 = e2.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
e2 = e2.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
e3 = mt_merge( mt_lutxy(e, e2 , "y x - "+string(blur2)+" * x +" , u=0, v=0), \
mt_lutxy(e, e2 , "x y - "+string(sharp2)+" * x +" , u=0, v=0), \
m12, u=0, v=0)
e3 = e3.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
e3 = e3.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
e3 = e3.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
e3 = e3.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
#aux= c.bilinearresize(dx, dy)
#e = e3.vaguedenoiser(wiener=true, wavelet=1, nsteps=9, auxclip=aux, wratio=2, chromat=2, threshold=3)
mt_merge(d4, e3, m2, u=0, v=0)
mergechroma(spline36resize(c, dx, dy), 1)
return(last)
}
[edit] updated script description
I would also like to thank everyone that contributed to the last thread, your help was indispensable.
function Lanczosplusv3( clip c, int "dx", int "dy", int "thresh", int "thresh2", float "aa2s",
\ float "sharp1", float "sharp2", float "blur1", float "blur2",
\ int "mtaps1", int "mtaps2", int "ttaps", int "ltaps", float "cstr",
\ int "depth", float "wthresh", float "wblur", float "aa", float "aa2")
{
# Requires : Masktools 2; Frfun7; fft3dfilter; aWarpsharp
# Instructions : This function performs best when enlarging by a factor of 2,
# performance degrades steadily the when enlarging by significantly larger or smaller factors
# if you have extensive aliasing in the resized image, experiment with aa values of 1.01-2.01,
# and aa2 values of 8-16, cstr varies the strength of sharpening, halo reduction and ringing
# cuncurrently, higher values add more sharpening and halo reduction, etc.
# for more exact control use the sharp1/2 and blur1/2 values
# the other valuse defaults are genearlly optimal, but feel free to experiment and report results
# note that if your source is blurry, the line detection routines will not work, and the interpolated
# picture will be blurry aswell, there is no way around this, if blurry things are treated like lines
# then artifacts will be created on gradients, and out of focus areas
# example usage : lanczosplus(1280, 720, cstr=1.5, depth=3)
dx = default(dx, c.width*2)
dy = default(dy, c.height*2)
cstr = default(cstr, 1.33)
thresh = default(thresh, 0)
thresh2 = Default(thresh2, ((thresh+1)*(thresh+1))*64/(thresh+1))
sharp1 = default(sharp1, cstr*0.125)
sharp2 = default(sharp2, cstr*1.0)
blur1 = default(blur1, cstr*0.5)
blur2 = default(blur2, cstr*0.25)
mtaps1 = default(mtaps1, 1)
mtaps2 = default(mtaps2, 1)
ttaps = default(ttaps, 3)
ltaps = default(ltaps, 7)
depth = default(depth, 3)
wthresh = default(wthresh, 0.70)
wblur = default(wblur, 1)
aa = default(aa, 0)
aa2 = default(aa2, 0)
aa2s = default(aa2s, 0)
c
s = c
fd1 = lanczosresize(c, dx, dy, taps=mtaps1)
fre1 = fd1.lanczosresize( c.width, c.height, taps=mtaps1)
fre2 = fre1.lanczosresize( c.width/2, c.height/2, taps=mtaps1).lanczosresize( c.width, c.height, taps=mtaps1)
m1 = mt_lutxy(fre1, s, "x y - abs "+string(thresh)+" - "+string(thresh2)+" *", u=0, v=0)
m2 = lanczosresize(lanczosresize(frfun7(m1, 2.01, 256, 256), c.width/2, c.height/2, taps=ttaps), \
dx, dy, taps=ttaps)
d = c#mt_merge(c, fre2, m1, u=0, v=0)
d2 = d.lanczosresize(dx, dy, taps=ttaps)
d3 = lanczosresize(lanczosresize(d, (c.width)-(width/2), (c.height)-(height/2), taps=ttaps), \
d2.width, d2.height, taps=ttaps)
d4 = mt_merge( mt_lutxy(d2, d3 , "x y - "+string(sharp1)+" * x +" , u=0, v=0), \
mt_lutxy(d2, d3 , "y x - "+string(blur1)+" * x +" , u=0, v=0), m2, u=0, v=0)
d5 = d4.lanczosresize(d.width, d.height, taps=ttaps)
e = mt_merge(d5, c, m1).lanczosresize(dx, dy, taps=ltaps)
e = aa >= 0.1 ? e.frfun7(aa, 256, 256) : e
e = aa2 >= 0.1 ? e.fft3dfilter(bw=36, bh=36, ow=18, oh=18, bt=1, sigma=aa2, plane=0, sharpen=aa2s) : e
e = e.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
e = e.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
e = e.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
e = e.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
fd12 = lanczosresize(e, e.width*(dx/c.width), e.height*(dy/c.height), taps=mtaps2)
fre12 = fd12.lanczosresize( e.width, e.height, taps=mtaps2)
fre22 = fre12.lanczosresize( e.width/2, e.height/2, taps=mtaps2).lanczosresize( e.width, e.height, taps=mtaps2)
m12 = mt_lutxy(fre12, e, "x y - abs "+string(thresh)+" - "+string(thresh2*1)+" *", u=0, v=0)
m12 = m12.lanczosresize( e.width/2, e.height/2, taps=mtaps2).lanczosresize( e.width, e.height, taps=mtaps2)
e2 = lanczosresize(lanczosresize(e, (c.width)-(width/2), (c.height)-(height/2), taps=ltaps), \
e.width, e.height, taps=ltaps)
e2 = e2.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
e2 = e2.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
e2 = e2.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
e2 = e2.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
e3 = mt_merge( mt_lutxy(e, e2 , "y x - "+string(blur2)+" * x +" , u=0, v=0), \
mt_lutxy(e, e2 , "x y - "+string(sharp2)+" * x +" , u=0, v=0), \
m12, u=0, v=0)
e3 = e3.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
e3 = e3.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
e3 = e3.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
e3 = e3.awarpsharp(depth=depth, cm=0, blurlevel=wblur, thresh=wthresh)
#aux= c.bilinearresize(dx, dy)
#e = e3.vaguedenoiser(wiener=true, wavelet=1, nsteps=9, auxclip=aux, wratio=2, chromat=2, threshold=3)
mt_merge(d4, e3, m2, u=0, v=0)
mergechroma(spline36resize(c, dx, dy), 1)
return(last)
}
[edit] updated script description