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.7, 3.8, 3.9, 3.10 and 3.11 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.7.tar.gz (156.2 kB view details)

Uploaded Source

Built Distributions

tinyscaler-1.2.7-cp311-cp311-win_amd64.whl (84.8 kB view details)

Uploaded CPython 3.11 Windows x86-64

tinyscaler-1.2.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (563.8 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

tinyscaler-1.2.7-cp311-cp311-macosx_10_9_universal2.whl (182.0 kB view details)

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

tinyscaler-1.2.7-cp310-cp310-win_amd64.whl (84.6 kB view details)

Uploaded CPython 3.10 Windows x86-64

tinyscaler-1.2.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (517.1 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

tinyscaler-1.2.7-cp310-cp310-macosx_11_0_x86_64.whl (96.4 kB view details)

Uploaded CPython 3.10 macOS 11.0+ x86-64

tinyscaler-1.2.7-cp39-cp39-win_amd64.whl (85.2 kB view details)

Uploaded CPython 3.9 Windows x86-64

tinyscaler-1.2.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (519.5 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

tinyscaler-1.2.7-cp39-cp39-macosx_11_0_x86_64.whl (97.3 kB view details)

Uploaded CPython 3.9 macOS 11.0+ x86-64

tinyscaler-1.2.7-cp38-cp38-win_amd64.whl (85.2 kB view details)

Uploaded CPython 3.8 Windows x86-64

tinyscaler-1.2.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (532.3 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

tinyscaler-1.2.7-cp38-cp38-macosx_11_0_x86_64.whl (97.5 kB view details)

Uploaded CPython 3.8 macOS 11.0+ x86-64

tinyscaler-1.2.7-cp37-cp37m-win_amd64.whl (84.6 kB view details)

Uploaded CPython 3.7m Windows x86-64

tinyscaler-1.2.7-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (490.9 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

tinyscaler-1.2.7-cp37-cp37m-macosx_11_0_x86_64.whl (97.0 kB view details)

Uploaded CPython 3.7m macOS 11.0+ x86-64

File details

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

File metadata

  • Download URL: tinyscaler-1.2.7.tar.gz
  • Upload date:
  • Size: 156.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for tinyscaler-1.2.7.tar.gz
Algorithm Hash digest
SHA256 1c0b34b41cca3ae9b09c20fee27499833345b9264617bdd23c896733676d82d8
MD5 0da71a928a0d24a90f66a664749c60aa
BLAKE2b-256 eb2aec77996374074810119493bd54a906f5d060bfcf8a4df31d1eba39a19429

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tinyscaler-1.2.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c14d302cd609d8c8e53ddf15b3ab43fa3c975d648ffcf16276c8b131ab849f85
MD5 cf5f1fbd9c64758916527010e05a3eeb
BLAKE2b-256 2d2efc26eac8b54ab8c939f640fd5981786e8b2630cd639d4600ce48e9e00cfd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tinyscaler-1.2.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7d2d129f71c518d9c0c25f5e9f3a7f7a31af62e7e7e6f8750ddf0154ed76a58a
MD5 86e9fa4f49f8d7bc943ef651d23c0263
BLAKE2b-256 eee822ab483b56214a5821bb185a98a3ea11b1bdc17dad4e02aafd1fdda69c2e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tinyscaler-1.2.7-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 bf63243a08e214e3db149435741b779db357c376636e17ddf153bf9f6ada041c
MD5 849f574aad1221e03ed6e22b8d1ca93c
BLAKE2b-256 ef63f68faf80475684e9971f61e85f62f7b1f4b5ac3b1f31bc97c858f4cceba4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tinyscaler-1.2.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a96f008975d4d167102a2671fb54fb6ace6ff2580fede3b79daeca99a01e5d6e
MD5 326fbb310a2e945790055578531dded6
BLAKE2b-256 0d81f56a68b0b694dc18e8c513f6e93155ec1c2dc83bf24ebe884a14198e722f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tinyscaler-1.2.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d062e0e33f6104d625fff9b57aa53511c39d2dc3bb711686f6992a7fbfe41336
MD5 6ea342b917e19a7f399d76643d0f52fb
BLAKE2b-256 e21c5fba52419ce683905bee015bb73c178dd72871b9211495b3b194ccd26f29

See more details on using hashes here.

File details

Details for the file tinyscaler-1.2.7-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for tinyscaler-1.2.7-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 bbb98ced396d4829a41aa9c7c895df4bcb3801a3bbe963978c90d12b07110731
MD5 0f737a780c06429d7b87ab5de0ed0696
BLAKE2b-256 4d75e5bf4d5141be9bd2d2b09238f50f3e409f4e4be9e506d751b88c96539b55

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tinyscaler-1.2.7-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 ce1e10fc54d02bb49ea1f72f76d320c50739eb4ff3e6cbb82148b4f84272220b
MD5 75a880e0b241dc54f77dd7ffbc06e577
BLAKE2b-256 bb7035d0061d2a2d25e5f1023209e9ad7435691863e70521f346e7e079d2cefc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tinyscaler-1.2.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9d86fe85fa37cfaedb521c9eb3a804b6ab202924be221049b784220c5ca49546
MD5 d9af5a397e8088cc50c2b28a5beacd3d
BLAKE2b-256 e0f8a60b0f56024330d3cf9f15c66a863bb3d788287b86549100500c179ce3c8

See more details on using hashes here.

File details

Details for the file tinyscaler-1.2.7-cp39-cp39-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for tinyscaler-1.2.7-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 2847420c81064c8bd3397bdcd83e2706cd914cdb9cbde5300ed968c14954b9d3
MD5 a661d84f364b991c94b64c643ce5133e
BLAKE2b-256 992b3af13cae65b378bff58abd937b6b7227864db6b36fde1b251a68839022f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tinyscaler-1.2.7-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 8e6b605ef00fc65a27f294742514f67d9b4c37d41bfe586e2609ab03a41f2e74
MD5 85e6634f6b8768fd3c1e2e671f34765f
BLAKE2b-256 67fc180c6a5bd719b9849bbd6633e6e8d0690d5fae86e6645746c214af19c97c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tinyscaler-1.2.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ef4843aaa2647d7ae7a26ba66dbd1d1b31d161ca558f2c385bc6b02277d27fdb
MD5 2459a7b322b3de361fa3c0ddd84e9277
BLAKE2b-256 d4c31ea335c680d6624150e63f4ebbbe7e911aeb2982b901c5f7d9722576b641

See more details on using hashes here.

File details

Details for the file tinyscaler-1.2.7-cp38-cp38-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for tinyscaler-1.2.7-cp38-cp38-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 f80203589d883896c86fe94165967be453fbb0fe47c9bc64521aee15e125f202
MD5 c22f7f032219e2e5d8e0b72a80f6b45b
BLAKE2b-256 60af9b04e56d74d2bb6a63d8797d065913caed4869209a4ae9a57905fec41801

See more details on using hashes here.

File details

Details for the file tinyscaler-1.2.7-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for tinyscaler-1.2.7-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 26d488778686392a0441e598df7ebc45ad014663e60384ef6170dd793f80d275
MD5 65d5d19fd2ff6ac502ed9c11bac53587
BLAKE2b-256 57a83409c64a71dc478e312c52c38a83c04f330aeb7d8abd3e34b5fd84939b9d

See more details on using hashes here.

File details

Details for the file tinyscaler-1.2.7-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tinyscaler-1.2.7-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c6700a37bd42615944099994f2aa473be215e25d79803fcac9de849205c7b149
MD5 6a5645d463f6c98f3e181fd03cbecf6c
BLAKE2b-256 3d3eef6f27a13ff6aaa54d6c0d0caea976c367caa886cf96abf404d859500b96

See more details on using hashes here.

File details

Details for the file tinyscaler-1.2.7-cp37-cp37m-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for tinyscaler-1.2.7-cp37-cp37m-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 3ef723fbe119614dfdd8a7bd40d73c17defaac6765f60c44693858bd5cd70fbc
MD5 c6084a215d9dac633df256b7b38ffcfd
BLAKE2b-256 0f90295d8f393b0696061a92b9a2c05ac83c44d3ef9b9c7bd45aea4a1f6d1bd2

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