Log in

View Full Version : 5 new interpolation kernels (via DitherTools)


*.mp4 guy
12th October 2012, 06:24
They are made available through a simple function "firniture".

example usage:firniture(720, 400, kernel="noalias4", gamma=false)

The different interpolation methods are selected via the kernel string. The available options are as follows.

"binomial5", "binomial7": A binomial windowed sinc filter with 5 or 7 taps. Should have the least ringing of any available interpolator, except perhaps "noaliasnoring4".

"maxflat5", "maxflat8": 5 or 8 tap interpolation that is maximally flat in the passband. In English, these filters have a sharp and relatively neutral look, but can have ringing and aliasing problems.

"noalias4": A 4 tap filter hand designed to be free of aliasing while having acceptable ringing and blurring characteristics. Not always a good choice, but sometimes very useful.

"noaliasnoring4": Derived from the "noalias4" kernel, but modified to have reduced ringing. Other attributes are slightly worse.

"wall7": A windowed sinc function intended to be an alternative to high-tap lanczos. [edit] removed because it wasn't actually any better.

taps: [edit] Thanks to Didée pointing out some oversights on my part (I threw the baby out with the bathwater when I found StrCmpi() to be 2.6 only) , this parameter is now mostly superfluous. It has been retained so that you can truncate the kernels to shorter taps then they would normally use

gamma: Set to true to turn on gamma correction for the y channel. Off by default.

Otherwise it may be used as any of avisynths internal resizing functions; However, due to the method in which dithertools utilizes custom coeficients, accuracy will decrease when resizing by more then a factor of two. Maximum accuracy is only technically achieved when resizing by an exact factor of two, either up or down. This is most likely to manifest when using the non-sinc derived kernels, but is not generally an issue.

function firniture(clip c, int width_, int height_, string "kernel", int "taps", bool "gamma")
{
binomial5 = string("8 0 -589 0 11203 0 -93355 0 606836 1048576 606836 0 -93355 0 11203 0 -589 0 8")
binomial7 = string("146 0 -20294 0 744006 0 -11528384 0 94148472 0 -487836876 0 2551884458 4294967296 2551884458 0 -487836876 0 94148472 0 -11528384 0 744006 0 -20294 0 146")

maxflat5 = string("-259 1524 -487 -12192 17356 42672 -105427 -85344 559764 1048576 559764 -85344 -105427 42672 17356 -12192 -487 1524 -259")
maxflat8 = string(" 2 -26 166 -573 912 412 1524 -589 -12192 17356 42672 -105427 -85344 606836 1048576 606836 -85344 -105427 42672 17356 -12192 -589 1524 412 912 -573 166 -26 2 ")

noalias4 = string("-1 2 4 -6 -17 7 59 96 59 7 -17 -6 4 2 -1")
noaliasnoring4 = string("-1 8 40 -114 -512 360 3245 5664 3245 360 -512 -114 40 8 -1")

kernel_ = Default(kernel, "binomial7")
taps = Default(taps, int(value(rightstr(kernel,1))))
gamma = default(gamma, false)

in = c
out = in.Dither_convert_8_to_16
out = gamma ? out.Dither_y_gamma_to_linear : out
out = out.Dither_resize16(width_, height_, 0, 0, 0, 0, kernel="impulse "+string(Eval(kernel_))+"", kovrspl=2, taps=taps)
out = gamma ? out.Dither_y_linear_to_gamma : out
out = out.DitherPost

return(out)
}
[edit] updated the no-alias kernels, removed wall7 (it wasn't useful).
[edit2] remembered to update the example usage so that it functions after the changes.

Didée
12th October 2012, 08:03
taps = int(value(rightstr(kernel,1)))
or did I miss something?

cretindesalpes
12th October 2012, 08:45
taps: Unfortunately a simple method of setting this automatically based on the selected kernel eluded me
[...]
However, due to the method in which dithertools utilizes custom coeficients, accuracy will decrease when resizing by more then a factor of two.
I'll try to fix theses issues in the next Dither release.

*.mp4 guy
12th October 2012, 09:00
taps = int(value(rightstr(kernel,1)))
or did I miss something?
No, I had the same idea (that is why the names are formatted that way), but iirc Avisynth 2.6 is required for rightstr, and it breaks some of my scipts. However, its nice to have the syntax presumably sorted out for when 2.6 becomes stable.

I'll try to fix theses issues in the next Dither release.It wasn't meant as a criticism, the way dithertools does things now is in no way defective. Doing things better as far as accuracy is concerned may be complicated, though theoretically polynomial or spline interpolation should be fine.

Didée
12th October 2012, 09:32
Why should 2.5.8 not have rightstr() ?

a=rightstr("onetwothr33",1)
version().subtitle(string(a),y=32)
http://thumbnails106.imagebam.com/21478/5dd4c6214775038.jpg (http://www.imagebam.com/image/5dd4c6214775038)

*.mp4 guy
15th October 2012, 01:29
Thanks for the help, Didée. I've been in the middle of moving, so it may take me a while to address the issue (no internet at the new place yet). If there is any interest, I'll also try to get around to putting up some examples or something as well.

*.mp4 guy
19th October 2012, 05:49
The first post has an updated version of firniture that no longer requires setting taps manually.

[edit] The "noalias4" kernel has been updated, and is now significantly sharper
Additionally, here is a sample (http://www.imagebam.com/image/70f2db215896487) of the lighthouse image interpolated 4X by the "noalias4" kernel. Compare it to this interpolation (http://www.imagebam.com/image/474abf215896500) using the standard spline36 kernel.

Keep in mind that these kernels are intended to be used for downscaling, or relatively small resolution adjustments. The comparison is done on upscaling because it makes the differences much easier to see. As should be clear, the "noalias4" kernel has very very good alias suppression, but is not quite as sharp as other kernels.

Each of the provided kernels is intended to fill a niche for which there currently exists no satisfactory solution in Avisynth. Obviously, using a low aliasing kernel on a blurry source would be a bad idea, but its great for those times when your stuck with an over-sharp source that is tripping up normal downscalers (or format shifters, etc.).

Reel.Deel
8th September 2014, 17:42
@*.mp4 guy

I think line 15 may contain a small typo. If I try firniture(540,540, kernel="binomial7") it works but if I use firniture(540,540) I get this error: Script error: Invalid arguments to function "rightstr".
Adding _ to kernel in line 15 solves it, is that what you intended? taps = Default(taps, int(value(rightstr(kernel_,1))))

StainlessS
8th September 2014, 19:16
It does not say on *.mp4.guy's profile when he was last about, so,

Kernel is an optional arg, and if omitted will be at that point in script, Undefined().

So, is probably what was intended (EDIT: "kernel_" was intended).