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) Thanks. Nicolas
On Sat, 13 Dec 2014 16:53:06 +0100
"Nicolas P. Rougier"
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 selfcontained 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
Thanks Jérôme, I will look into your code. Having other filter might be useful for my case. While looking for code, I've also found this (pure python) implementation: http://stackoverflow.com/questions/12729228/simpleefficientbilinearinterp... Nicolas
On 14 Dec 2014, at 09:03, Jerome Kieffer
wrote: On Sat, 13 Dec 2014 16:53:06 +0100 "Nicolas P. Rougier"
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 selfcontained 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 _______________________________________________ NumPyDiscussion mailing list NumPyDiscussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpydiscussion
On Sun, 14 Dec 2014 12:52:03 +0100
"Nicolas P. Rougier"
Thanks Jérôme, I will look into your code. Having other filter might be useful for my case.
While looking for code, I've also found this (pure python) implementation: http://stackoverflow.com/questions/12729228/simpleefficientbilinearinterp...
Great, I keep the link as well. it is interesting to have it. The only drawback is the poor cache efficiency of the numpy implementation (where actually cython rocks) Cheers,  Jérôme Kieffer Data analysis unit  ESRF
participants (2)

Jerome Kieffer

Nicolas P. Rougier