Lanczos Resampling With ActionScript

It has been a while since I worked on some interesting library. But the day has come 🙂 and here it is. Let me introduce you LanczosBitmapDataResizer class. Lanczos resampling is an interpolation method used to compute new values for sampled data. In resampling (resizing) images it is considered to be one of the best algorithms at all. Lanczos is a convolution filters. That means a filter that for each output value moves the convolution functions point of origin to be centered on the output and then multiplies all the values in the input with the value of the convolution function (kernel) at that location and adds them together.

The most common lanczos filter size is 3. It means that each output pixel is defined by its +- 3 pixel box. The kernel function than looks something like this:


While there is a lot of iterations and computing within my algorithm, I ivite you all to help me optimize the code.

Lanczos Resampling – wonderfl build flash online

More sources:

5 comments so far

  1. […] Update November 10, 2010: Lanczos Resampling With ActionScript […]

  2. Mario Klingemann November 10, 2010 14:46

    Oh that will come in handy – thanks for implementing this. I had a quick look at the code and made some minor optimizations, mainly inlining the lanczos call in the inner loop – doesn’t really speed it up much, but a little:

  3. Jozef Chúťka November 10, 2010 15:10

    thank you Mario

  4. Slavomir Durej November 10, 2010 16:54

    Nice work Jozef. Quite useful class!
    some questions.. is the image quality better (for downscaling) using this method or bicubic/bilinear interpolation ?
    Have you thought of using Pixel Bender for this ?
    Have you got any restrictions on usage (i.e. what’s licencing on this?)

  5. Jozef Chúťka November 10, 2010 17:59

    Hi Slavomir, thnx
    there is a lot discussion online about which algorithm is better and for what purpose – some leaves more artifacts some less, some leaves more details some less (sharpen, blured) for video compression you need less size thus less details… What is better is up to you. Try downscale (2x, 4x, 7x) the same image (I use images with text) to see the difference for each algorithm… Lanczos is my personal best when using IrfanView
    While there is are no loops in current pixel bender, it would only be possible to use it only for the latest section of process (where you get the color of source pixels and process it into resulting one) but for that purpose you would have to manufacture source vectors/bitmapdata for each resulting pixel… it surely will be worth of testing – this part now takes something like 30% of processing time
    For licensing pls read

Leave a comment

Please be polite and on topic. Your e-mail will never be published.