[Numpy-discussion] Bilinear interpolation (numpy only)

Jerome Kieffer Jerome.Kieffer at esrf.fr
Sun Dec 14 03:03:47 EST 2014


On Sat, 13 Dec 2014 16:53:06 +0100
"Nicolas P. Rougier" <Nicolas.Rougier at inria.fr> wrote:

> 
> Hi all,
> 
> Does anyone has a simple 2D linear interpolation for resizing an image (without scipy) ?
> 
> Ideally, something like ```def zoom(Z, ratio): ...``` where Z is a 2D scalar array and ratio the scaling factor.
> (I'm currently using ```scipy.ndimage.interpolation.zoom``` but I would like to avoid the scipy dependency)

Hi Nicolas,

I have a self-contained cython class for that:
https://github.com/kif/pyFAI/blob/master/src/bilinear.pyx

The formula for bilinear interpolation in implemented there but it
needs some additionnal work for what you want to do.

Beside this I implemented an antialiased downscaler using Lanczos (order 1, 2 or 3)
https://github.com/kif/imagizer/blob/qt/src/down_sampler.pyx.

Create a downscaler:
ds = down_sampler.DownScaler()
scaled_img = ds.scale(img, 4.5)

In this case the interpolation will be done on a vinicy of (2*4.5*3+1) pixel in the input image (and 2*3+1 in the output image) as it is doing Lanczos 3 by default.
This implementation is 2x faster than the Antialiased downscaler in PIL.

Cheers,

-- 
Jérôme Kieffer
Data analysis unit - ESRF



More information about the NumPy-Discussion mailing list