Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 7th April 2008, 07:11   #1  |  Link
*.mp4 guy
Registered User
 
*.mp4 guy's Avatar
 
Join Date: Feb 2004
Posts: 1,348
New (sort of) version of lanczosplus (interpolator)

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.

Code:
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

Last edited by *.mp4 guy; 7th April 2008 at 11:34.
*.mp4 guy is offline   Reply With Quote
Old 7th April 2008, 07:12   #2  |  Link
*.mp4 guy
Registered User
 
*.mp4 guy's Avatar
 
Join Date: Feb 2004
Posts: 1,348
spot reserved.
*.mp4 guy is offline   Reply With Quote
Old 7th April 2008, 19:00   #3  |  Link
Atak_Snajpera
RipBot264 author
 
Atak_Snajpera's Avatar
 
Join Date: May 2006
Location: Poland
Posts: 7,803
Any examples? 1080->720
Atak_Snajpera is offline   Reply With Quote
Old 7th April 2008, 19:28   #4  |  Link
buzzqw
HDConvertToX author
 
Join Date: Nov 2003
Location: Cesena,Italy
Posts: 6,552
Quote:
Originally Posted by Atak_Snajpera View Post
Any examples? 1080->720
look here

Quote:
Originally Posted by *.mp4 guy
Instructions : This function performs best when enlarging by a factor of 2,
BHH
__________________
HDConvertToX: your tool for BD backup
MultiX264: The quick gui for x264
AutoMen: The Mencoder GUI
AutoWebM: supporting WebM/VP8
buzzqw is offline   Reply With Quote
Old 7th April 2008, 19:49   #5  |  Link
Dark Shikari
x264 developer
 
Dark Shikari's Avatar
 
Join Date: Sep 2005
Posts: 8,666
If its primarily made for resizing up by a factor of 2, what benefit does this give over NNEDIresize?
Dark Shikari is offline   Reply With Quote
Old 7th April 2008, 23:35   #6  |  Link
*.mp4 guy
Registered User
 
*.mp4 guy's Avatar
 
Join Date: Feb 2004
Posts: 1,348
Quote:
Originally Posted by Dark Shikari View Post
If its primarily made for resizing up by a factor of 2, what benefit does this give over NNEDIresize?
Faster, sharper, more natural looking on film content, but it usually does alias more, lines are also thinner.

[edit]
lanczosplus: clown, Bricks
nnedi: clown, Bricks

note that nnedi has a subpixel shift, which is why the images do not line up perfectly.

Last edited by *.mp4 guy; 8th April 2008 at 00:34.
*.mp4 guy is offline   Reply With Quote
Old 8th April 2008, 01:21   #7  |  Link
unskinnyboy
Registered User
 
unskinnyboy's Avatar
 
Join Date: Feb 2004
Location: NTSC R1
Posts: 2,046
Quote:
Originally Posted by *.mp4 guy View Post
Faster, sharper, more natural looking on film content, but it usually does alias more, lines are also thinner.

[edit]
lanczosplus: clown, Bricks
nnedi: clown, Bricks

note that nnedi has a subpixel shift, which is why the images do not line up perfectly.
Are both examples FiLM? I find nnedi much better in this comparison - lanczosplus has strong aliasing, resulting in an oil paint look. nnedi looks more natural. Can you tweak your aa, aa2, cstr values to match nnedi, or this is it?
__________________
unskinnyboy is offline   Reply With Quote
Old 8th April 2008, 01:42   #8  |  Link
Nagisa_chan
bad encoder
 
Nagisa_chan's Avatar
 
Join Date: Mar 2008
Location: colombia
Posts: 8
nnedi dont have aliasing... for me, is best than lanczosplus....

i am novice
Nagisa_chan is offline   Reply With Quote
Old 8th April 2008, 04:16   #9  |  Link
MfA
Registered User
 
Join Date: Mar 2002
Posts: 1,075
Linear interpolators with negative taps throw in some (un)sharpening with their interpolation, NNEDI doesn't (it's intended to be used with non blurred pixels from fields after all). With this kind of use NNEDI will always give a less sharp result, but you can always sharpen it up.
MfA is offline   Reply With Quote
Old 8th April 2008, 13:15   #10  |  Link
*.mp4 guy
Registered User
 
*.mp4 guy's Avatar
 
Join Date: Feb 2004
Posts: 1,348
Quote:
Originally Posted by MfA View Post
Linear interpolators with negative taps throw in some (un)sharpening with their interpolation, NNEDI doesn't (it's intended to be used with non blurred pixels from fields after all). With this kind of use NNEDI will always give a less sharp result, but you can always sharpen it up.
Well, no you can't actually, sharpening nnedi just emphasizes how thick the lines are, believe me, I've tried. Not to mention, that unfortunately nnedi is never completely free of aliasing, so sharpening will always reveal further artifacts, that are often hidden by the blur.

To address the other questions, the default settings were used on both images, iirc I might have lowered depth slightly for the clown image, because its a 4x upsize, with aa its possible to have less aliasing then nnedi, while maintaining thinner, lines, but detail gets destroyed (not that much wore then nnedi, on cartoons/cg, but pretty horrible for well defined texture, like the bricks image); its only really worth it on anime or cg, imo.

Anyway, I'm not here to convince you to use it, test it for yourself, no need to tweak anything, just lanczosplus() is fine.
*.mp4 guy is offline   Reply With Quote
Old 8th April 2008, 15:56   #11  |  Link
WorBry
Registered User
 
Join Date: Jan 2004
Location: Here, there and everywhere
Posts: 1,197
Nnediresize_YV12() and a light LimitedSharpen (with or without further internal resizing) looks cleaner and more natural to me, at least for upscaling my MCBobbed 50p and pseudo-progressive 25p (frame mode) DV sources. LanczosPLus shows more aliasing and ringing.

Incidentally, I wonder if any one has compared these upsizing routines with commercial applications, like Red Giant's Instant HD? Unfortunately, I dont have AfterEffects and so cant test myself.
__________________
Nostalgia's not what it used to be

Last edited by WorBry; 8th April 2008 at 16:03.
WorBry is offline   Reply With Quote
Old 11th April 2008, 16:05   #12  |  Link
Prettz
easily bamboozled user
 
Prettz's Avatar
 
Join Date: Sep 2002
Location: Atlanta
Posts: 373
Lanczosplus definitely looks sharper, and I think slightly better overall, but it's too bad about that aliasing. Also, in the clown image, check out those ringing artifacts around the lightpost. It's not that noticeable, but could result in some very unfortunate side effects once it's time to encode.
Prettz is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:11.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.