Fast image interpolation
Project description
pynterpol
Fast image interpolation in Python.
Installation
python -m pip install pynterpol
Usage (example)
from pynterpol import interp_bilinear_u8
import cv2
img = cv2.imread('image.jpg') # or any other way of reading an image as a numpy ndarray
interpolated_values = interp_bilinear_u8(img, [100.1, 100.8], [50.5, 51.2])
Performances
High performance is achieved:
- by considering that the image to interpolate is defined on an orthogonal equally-spaced regular grid, and
- by using Numba for the loop-intensive parts of the computation, and
- by optimizing the algorithm implementation (avoid code cache misses for special cases, etc.)
Comparative Timings
Timings realized on an Apple MacBook Pro (Intel Core i9 8 cores, 2.3 GHz) with an gray (i.e. single channel) image of size 1904x1081x1 interpolated on a regular equally-spaced grid of size 3807x2161 that covers the entire domain of the image (that corresponds to a x2 upsampling of the input image).
| method | timings |
|---|---|
SciPy RegularGridInterpolator |
1614 ms |
interp_bilinear_u8 (without Numba) |
82980 ms (LOL) |
interp_bilinear_u8 (with Numba) |
65 ms (almost x25 speedup) |
Reference
As of 2022-03-06, only images represented as a NumPy ndarray with uint8 as dtype are supported. Interpolated values are
stored as float64. All of this is implemented with a single function: interp_bilinear_u8.
Other cases may be considered in the future:
- bicubic interpolation or other interpolation schemes
- image represented with different types (float, bigger uints, ...)
- integer (or smaller floats) interpolated values
Tests
cd $PROJECT_ROOT
PYTHONPATH=./src python -m unittest tests.test_pynterpol.TestPynterpol
Note: There may be a better way than providing the PYTHONPATH variable in the command...
Distribution
python -m pip install --upgrade build twine
python -m pip build
python -m twine upload --repository testpypi dist/*
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pynterpol-1.1.0.tar.gz.
File metadata
- Download URL: pynterpol-1.1.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ce9fe279bf82eec73eea4467f82f925f992cdbb7ed9ac0164e4dea850ee8a27
|
|
| MD5 |
d01bcaaf43d9b801519258c28248ca8b
|
|
| BLAKE2b-256 |
79b3c814a9707d186d8e39f85f2187bc56434e81c72a64c5bf280cf686dcecf3
|
File details
Details for the file pynterpol-1.1.0-py3-none-any.whl.
File metadata
- Download URL: pynterpol-1.1.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a7a4d7156748d655bb0ec2b7b759f3b37ff794fbbf5cf45a657b736558d6a80
|
|
| MD5 |
435682f0662c82b9abfc9fb24eb40660
|
|
| BLAKE2b-256 |
5652fa1ebbab59373d233d00dcc46ccde573e97ea95f64027f5bedc29fde32c5
|