Log in

View Full Version : spline16 (or general resizers) implementation question


wonkey_monkey
6th December 2009, 23:14
Hi,

I'm writing a filter which, as part of its function, resizes an image in memory (it's easier this way). I've used spline16, taking the weight formula from http://www.all-in-one.ee/~dersch/interpolator/interpolator.html, but with high scaling factors the result from AviSynth's spline16 is much better. What is spline16resize doing to reduce aliasing?

http://img709.imageshack.us/img709/9849/resizers.png

Left: mine, Right: AviSynth (scale from original: 1/16)

I wasn't planning to use such a high reduction in the filter (not without scaling down in steps) but seeing AviSynth's result got me wondering how it does it.

David

LoRd_MuldeR
6th December 2009, 23:18
See this:
on the theory of the Spline16/36/64 resizers (http://forum.doom9.org/showthread.php?t=147117)

:search:

wonkey_monkey
7th December 2009, 00:54
Hmm, doesn't tell me much - I know the basics of resampling but all this talk of polynomials makes my head hurt, and I'm not sure there's anything in there explaining how the resizers deal with aliasing. I've had a look at the source code, which didn't tell much either, but it did give me a few optimization pointers, and the thought that I should learn some assembler.

David

PS When I accidentally double-clicked the link to this thread just now, it momentarily turned into a text entry box, before Firefox loaded this page. What's the point of that functionality, if there's no time to edit the title before the page loads? Or am I missing something there, too...?

Gavino
7th December 2009, 01:23
See http://avisynth.org/mediawiki/Resampling.

Basically, when downsizing, the filter kernel width is extended to include more source pixels in inverse proportion to the scaling ratio.

wonkey_monkey
7th December 2009, 02:18
*lightbulb!*

Thanks Gavino, I think I get it now. This is going to take a little bit of thinking, since the scaling in my filter changes over time... back to the drawing board.

David

sh0dan
7th December 2009, 15:31
@davidhorman: I have implemented a "simpler" edition of the avisynth resampler, that recalculates the coefficients on every resample.

https://rawstudio.org/svn/rawstudio/trunk/plugins/resample/resample.c

Search for:
ResizeH(ResampleInfo *info)
ResizeV(ResampleInfo *info)

This is for 16bit images, but the algorithm is in C, so there should be much magic needed to adapt it..

wonkey_monkey
7th December 2009, 16:14
Thanks sh0dan, that helps too, though I think it'll be easier just to modify my code than yours - it's always the way ;)

I'm assuming this "increase filter size" trick can't really be used simply in more general cases of image resampling? Warping, etc...

David

MfA
8th December 2009, 01:59
If a first order approximation is sufficiently precise it can ... but "simply" is not a term I would apply to how it would work out, you need the derivative of the mapping function to determine the shape. The problem is that the shape will be anistropic in the general case and separable filtering no longer applies.

IMO anti-aliased image warping is better done with forward mapping (splatting).

wonkey_monkey
8th December 2009, 03:04
"Splatting"? That's a new one on me... let me guess though, you iterate over the source pixels and paint each one at varying weights over the target pixels it covers?

I've now successfully implemented scaling in my filter - it's horrendously slow but it gets the job done :)

David