Skip to main content

A tiny, simple image scaler.

Project description

A small CPU image scaling library with SIMD support on x86_64 and Arm (Neon). This project is aimed to replace OpenCV for image resizing, resolving installation inconveniences and compatibility issues. We developed this for future use in Gymnasium and PettingZoo wrappers.

Installation

You can install from PyPI using pip install tinyscaler. Linux and macOS with Python >=3.8 are supported.

Usage

Tinyscaler contains a single external function, scale that using a numpy array input for the image and the new resized shape, returns the resized image.

import numpy as np
import tinyscaler

img = np.random.rand(64, 64, 4).astype(np.float32)

resize_img = tinyscaler.scale(img, (32, 32))
print(resize_img.shape, resize_img.dtype)  # (32, 32) np.float32

TinyScaler supports mode='area', mode='bilinear', and mode='nearest' filtering. It also allows one to pass a destination buffer in order to avoid duplicate memory allocations.

Area filtering is only really useful for downscaling, bilinear will be used even when area filtering is set if upscaling. Area filtering is also likely not worth it when downscaling less than or equal to 2x.

TinyScaler is used through a single function. The full signature is:

scale(src : np.ndarray, size : tuple, mode='area', dst : np.ndarray = None)

Note that the size tuple parameter is (width, height). However, the numpy arrays have dimensions ordered as (height, width, channels). This is similar to OpenCV.

TinyScaler expects a contiguous numpy array. If it is not contiguous, it will throw an error. You can make a non-contiguous numpy array contiguous by calling np.ascontiguousarray. Usually a numpy array will already be contiguous.

If the final array dimension is not 4 (RGBA), it will automatically convert to it. Further, if the array is uint8, it will be converted to float32. So the prefered array has a shape (height, width, 4) and dtype=np.float32.

Finally, downscaling is the focus of TinyScaler. It can also upscale, but it will not be as fast as a more complex separable algorithm in that case.

Performance

In a simple benchmark, we resized the same image (4928x3279) down to (852x567) 100 times using bilinear filtering with several libraries. Here are the times (in seconds) spent (measured with Python's perf_counter) on a AMD 1950x:

Time elapsed for tinyscaler: 0.7968465110002398
Time elapsed for OpenCV: 0.48667862100001
Time elapsed for Pillow: 12.672875003999707
Time elapsed for skimage: 164.45401711399973

And with area filtering (just TinyScaler and OpenCV):

Time elapsed for tinyscaler: 4.34793155800071
Time elapsed for OpenCV: 8.118138265999733

All methods were forced to use a single thread. OpenCV is slightly faster than TinyScaler for bilinear filtering, but TinyScaler remains very fast regardless.

Interestingly, for area filtering, TinyScaler is faster (almost 2x).

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

tinyscaler-1.2.8.tar.gz (156.9 kB view details)

Uploaded Source

Built Distributions

tinyscaler-1.2.8-cp312-cp312-win_amd64.whl (83.8 kB view details)

Uploaded CPython 3.12 Windows x86-64

tinyscaler-1.2.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (563.6 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

tinyscaler-1.2.8-cp312-cp312-macosx_10_9_universal2.whl (179.8 kB view details)

Uploaded CPython 3.12 macOS 10.9+ universal2 (ARM64, x86-64)

tinyscaler-1.2.8-cp311-cp311-win_amd64.whl (84.0 kB view details)

Uploaded CPython 3.11 Windows x86-64

tinyscaler-1.2.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (563.3 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

tinyscaler-1.2.8-cp311-cp311-macosx_10_9_universal2.whl (178.3 kB view details)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

tinyscaler-1.2.8-cp310-cp310-win_amd64.whl (83.9 kB view details)

Uploaded CPython 3.10 Windows x86-64

tinyscaler-1.2.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (522.8 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

tinyscaler-1.2.8-cp310-cp310-macosx_10_9_universal2.whl (178.5 kB view details)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

tinyscaler-1.2.8-cp39-cp39-win_amd64.whl (84.5 kB view details)

Uploaded CPython 3.9 Windows x86-64

tinyscaler-1.2.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (524.8 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

tinyscaler-1.2.8-cp39-cp39-macosx_10_9_universal2.whl (179.7 kB view details)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

tinyscaler-1.2.8-cp38-cp38-win_amd64.whl (84.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

tinyscaler-1.2.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (534.4 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

tinyscaler-1.2.8-cp38-cp38-macosx_11_0_universal2.whl (179.3 kB view details)

Uploaded CPython 3.8 macOS 11.0+ universal2 (ARM64, x86-64)

File details

Details for the file tinyscaler-1.2.8.tar.gz.

File metadata

  • Download URL: tinyscaler-1.2.8.tar.gz
  • Upload date:
  • Size: 156.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for tinyscaler-1.2.8.tar.gz
Algorithm Hash digest
SHA256 0ce3b77562f1db74b2035ccaf62807af043333ce655e71effd6ec85fbf8ded06
MD5 afbeaabe749f799cc506f29f9477c081
BLAKE2b-256 0d596b6495fe9bb3153306a4bd6dd24c78ff74eaf64f90fc6e545ede0574cfbe

See more details on using hashes here.

File details

Details for the file tinyscaler-1.2.8-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for tinyscaler-1.2.8-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6a7c18d9c082f30193bd23a6eb8ad84d2ee9b224138c8c25a76db96cba71a473
MD5 bd5348f696574e6abbc6404b804a8aa3
BLAKE2b-256 68d00b0abfde6acdf79b41ea685067a52d3e47f3b1fb4a0f4f49d9c6f281a3c7

See more details on using hashes here.

File details

Details for the file tinyscaler-1.2.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tinyscaler-1.2.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7474fe93740b0aa045e4e2ad60f8df6d5d570c4ea903c6d63ca3868efd8f4e22
MD5 cfb9b6f94d575cf183f8b401e5343624
BLAKE2b-256 b7cf528a73de4ad128de99bf7cc0e80f236aeeb36fda1e2768a7eb73210a91ff

See more details on using hashes here.

File details

Details for the file tinyscaler-1.2.8-cp312-cp312-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for tinyscaler-1.2.8-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 fcafd6a8b7ac8c8eabc560f99f987e3e9c00b32a5f3472b28ee865db9bf264b2
MD5 b3e5d107e3008c3597940d93fe32478f
BLAKE2b-256 4b6506fa456d375b71672affd292dd79f199b21a574eb0501afa142f85133b99

See more details on using hashes here.

File details

Details for the file tinyscaler-1.2.8-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for tinyscaler-1.2.8-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 93869b729bc2d596e2b2e0803d2f9e0e1a0baced6c96b8c21af178b3061b3fba
MD5 fb528eec28af32d804430bdf5624dffa
BLAKE2b-256 218fc064ace9fe32a3968eedd1ae19f079020f0fdd55e811dfd1c7a2b6cc442f

See more details on using hashes here.

File details

Details for the file tinyscaler-1.2.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tinyscaler-1.2.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a7dbf9f80ba08918c304261e2f8e3356eccbc925364b706cef2997f0abf0fc91
MD5 30738bef637bb29dc8f29dd397f06978
BLAKE2b-256 3b0ec52b316dccb2181521a5faca6ef404670e567dddb6f38cbd72175af23d49

See more details on using hashes here.

File details

Details for the file tinyscaler-1.2.8-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for tinyscaler-1.2.8-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 57ad9b0203e984ad140b31f0fe82f8bd82e4c31574461264a9a6e7f7d105eb50
MD5 36a41474e2d67f3d9aa8e2bdbd262180
BLAKE2b-256 01c9a2dbce5c9ecfaff4887bc0f5ff2288c678e25810801e84ddd737d4c0f3e8

See more details on using hashes here.

File details

Details for the file tinyscaler-1.2.8-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for tinyscaler-1.2.8-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 34d43fad3e09331b7a9259ee11ff4c209c31f00129b3a0c98480f7e43c789c2f
MD5 bf28c18af6d4f75820eb986c450b0c1c
BLAKE2b-256 707eb42030012265686e2f95f2449dd7e40b1e54d92a371f90b11c11bdd8b6c3

See more details on using hashes here.

File details

Details for the file tinyscaler-1.2.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tinyscaler-1.2.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fb30db6782df95c34b294266876e71fd3d32dd3d33bf4c8ec72d07f570ae7bca
MD5 6d9688b5a1630f5c6694556353defdf1
BLAKE2b-256 b7b23c38f6727b1618160248b6c56486eb006db153c2ca99381251343cd54376

See more details on using hashes here.

File details

Details for the file tinyscaler-1.2.8-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for tinyscaler-1.2.8-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 b69a0414d626ba5d075b93546f37ece0c10f690f7d3ce3f162c2316ac1667511
MD5 39b43522b6d91de754165950216121e1
BLAKE2b-256 96140b47fbc882faa2358fc205734bd4b872c84539ef8231bbf1ef2eb5e99506

See more details on using hashes here.

File details

Details for the file tinyscaler-1.2.8-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for tinyscaler-1.2.8-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 17409e85ff23d5eb29da65d6cdfdeafeb7d94b7c8051b1ab8457886ceb61b234
MD5 3b7a302fa8ee0b973d4fdbf450bd78d3
BLAKE2b-256 4f2f263d8d100c501959662986b065e91f9fc59e5ff4cecc0b511009eac97711

See more details on using hashes here.

File details

Details for the file tinyscaler-1.2.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tinyscaler-1.2.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 aa5eb3d4ba1fb803e1616fde7f58126355a47c6ca79c3393907e21c677bc5d37
MD5 856c37f3426f4599cde9895320ae8428
BLAKE2b-256 eb31c54ebf036e092cc31ecfd7ccc2970165ce72679f3c1be43f7cddc1aa5e2d

See more details on using hashes here.

File details

Details for the file tinyscaler-1.2.8-cp39-cp39-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for tinyscaler-1.2.8-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 3143352056dc9ac2ab87795fa3f36498c52ae603b76b3b73189544c588f46d77
MD5 ca77ca71a75966e7bd7eae2a80f1857b
BLAKE2b-256 6b1bb291ab1c819a1bca3e6fa1f924d5fa14fc12603504bc7f5cf63599fe7878

See more details on using hashes here.

File details

Details for the file tinyscaler-1.2.8-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for tinyscaler-1.2.8-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 a6fbaf0417e6b76c063431675d4f22090c5d34667f6cc5f7c6334e144053611d
MD5 f656969391060fe5e79aff56a546111a
BLAKE2b-256 112337dc9a8de2a4cdd8e85b38aa97f1bc8d7985b50f9b1d981336120fca1fd6

See more details on using hashes here.

File details

Details for the file tinyscaler-1.2.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tinyscaler-1.2.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7969396adaaaf65694e2cacda394922f6c1939afff7c1202f3a32ee9a0067e30
MD5 d8c57bc3fca30c66a854f5d373766cf6
BLAKE2b-256 c2f821cde699fcc1b75abc64e0d74c4551a116e30fd0f0e25fe97ce4dd8b2c81

See more details on using hashes here.

File details

Details for the file tinyscaler-1.2.8-cp38-cp38-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for tinyscaler-1.2.8-cp38-cp38-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 393aafdbbf0733cd328ee07b07ea3be442f640b232c0c3d31915ed047ea93162
MD5 b584702b89a9b851f134c4b7e3f0deab
BLAKE2b-256 bcc3278017fafb1ca9c66c7f520bcf66b73d501b0a4555d4b7b3eade464d5168

See more details on using hashes here.

Supported by

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