Skip to main content

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

pynterpol-1.0.5.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pynterpol-1.0.5-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file pynterpol-1.0.5.tar.gz.

File metadata

  • Download URL: pynterpol-1.0.5.tar.gz
  • Upload date:
  • Size: 4.9 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

Hashes for pynterpol-1.0.5.tar.gz
Algorithm Hash digest
SHA256 64882d8e420d59c46e590718530fbc0dbd57d508e65d7348a602c2b7f4e3b979
MD5 3ecb91ea4e8a6ee4fee599dec10d441a
BLAKE2b-256 2428e4cc6a65b8dcea4c9cc97eb576b2f6250a10e85ccd14279b60ef8f9d6b52

See more details on using hashes here.

File details

Details for the file pynterpol-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: pynterpol-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 5.0 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

Hashes for pynterpol-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 0194a09b859308aa51b8388454033f5191f9e98f877e213812ccf3281ef9911f
MD5 f48d33ac0bc11f88b9985c3ab052a272
BLAKE2b-256 a533e6e3a7214f0bdf9274ab6f917a259a20f09e4919098dff55d1baec12fb68

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page