Skip to main content

Fast image interpolation

Project description

pynterpol

Fast image interpolation in Python.

Installation

python -m pip install pynterpol

Usage (example)

from src.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.4.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.4-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pynterpol-1.0.4.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.4.tar.gz
Algorithm Hash digest
SHA256 3d4c9229082fe6107b5b755ccb0c38f10b520642bfb821333bdb3e6989426d67
MD5 948f668fe697c4fd9efbeda6277b4cb8
BLAKE2b-256 d3248f96f6765b8e110f1f72144b9a2dfffbfea0c3baaffd29a12fb279027ed0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pynterpol-1.0.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 554a0d993f3f3736be25ebd7f581d9dce1dd77743afd4102ad54b84d6c24b665
MD5 4e56b2d8c9abb7f9d1e03a2ec015c20d
BLAKE2b-256 8405dcc7dca8d15191b0147847e8cf71bc0b4491e169b86682da6e2388be1109

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