A fast image resizer
Project description
cykooz.resizer
cykooz.resizer
is package with optimized version of image resizing
based on Rust's crate fast_image_resize.
Installation
python3 -m pip install cykooz.resizer
Or with automatically installing Pillow:
python3 -m pip install cykooz.resizer[pillow]
Information
Supported pixel types and available optimisations:
U8x4
- four bytes per pixel (RGB, RGBA, CMYK):- native Rust-code without forced SIMD
- SSE4.1
- AVX2
I32
- one signed integer (32 bits) per pixel:- native Rust-code without forced SIMD
F32
- one float (32 bits) per pixel:- native Rust-code without forced SIMD
Implemented resize algorithms:
- Nearest - is nearest-neighbor interpolation, replacing every pixel with the nearest pixel in the output; for upscaling this means multiple pixels of the same color will be present.
- Convolution with different filters:
- box
- bilinear
- catmull_rom
- mitchell
- lanczos3
- Super sampling - resizing an image in two steps. First step uses the "nearest" algorithm. Second step uses "convolution" with configurable filter.
Usage Examples
Resize Pillow's image
from PIL import Image
from cykooz.resizer import FilterType, ResizeAlg, Resizer
resizer = Resizer(ResizeAlg.convolution(FilterType.lanczos3))
dst_size = (255, 170)
dst_image = Image.new('RGBA', dst_size)
for i in range(1, 10):
image = Image.open('nasa_%d-4928x3279.png' % i)
resizer.resize_pil(image, dst_image)
dst_image.save('nasa_%d-255x170.png' % i)
Resize raw image with alpha channel
from cykooz.resizer import AlphaMulDiv, FilterType, ImageData, PixelType, ResizeAlg, Resizer
def resize_raw(width: int, height: int, pixels: bytes):
src_image = ImageData(
width,
height,
PixelType.U8x4,
pixels,
)
alpha_mul_div = AlphaMulDiv()
resizer = Resizer(ResizeAlg.convolution(FilterType.lanczos3))
dst_image = ImageData(255, 170, PixelType.U8x4)
alpha_mul_div.multiply_alpha_inplace(src_image)
resizer.resize(src_image, dst_image)
alpha_mul_div.divide_alpha_inplace(dst_image)
return dst_image
Change used CPU-extensions
from cykooz.resizer import FilterType, ResizeAlg, Resizer, CpuExtensions
resizer = Resizer(ResizeAlg.convolution(FilterType.lanczos3))
resizer.cpu_extensions = CpuExtensions.sse4_1
...
Benchmarks
Environment:
- CPU: Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
- RAM: DDR4 3000 MHz
- Ubuntu 20.04 (linux 5.11)
- Python 3.8
- cykooz.resizer = "0.1"
Other Python libraries used to compare of resizing speed:
- Pillow = "8.1.3" (https://pypi.org/project/Pillow/)
Resize algorithms:
- Nearest
- Convolution with Bilinear filter
- Convolution with Lanczos3 filter
Resize RGBA image 4928x3279 => 852x567
- Source image nasa-4928x3279.png
Package (time in ms) | nearest | bilinear | lanczos3 |
---|---|---|---|
Pillow | 0.92 | 99.03 | 228.23 |
cykooz.resizer | 0.51 | 69.29 | 127.72 |
cykooz.resizer - sse4_1 | 0.51 | 25.66 | 39.11 |
cykooz.resizer - avx2 | 0.51 | 17.49 | 27.08 |
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 Distributions
File details
Details for the file cykooz.resizer-1.0.tar.gz
.
File metadata
- Download URL: cykooz.resizer-1.0.tar.gz
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e11ec37517eb2c33984dcd79a32a63bb92d7591470992a4fe565af885042637d |
|
MD5 | 7b6975f26318db18b870d80de802ce3f |
|
BLAKE2b-256 | 03474b19b9bdab99a5815a171ee928a79798997991b8a03e20da505983573a30 |
File details
Details for the file cykooz.resizer-1.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-1.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 221.7 kB
- Tags: CPython 3.10, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ea34bdd0ad0ea8798cbfb947373290736935dfdd2442670ab4174a7a3962b8f |
|
MD5 | 06237e213bcb37dece103c224c9ca838 |
|
BLAKE2b-256 | d6f8b085ee3367c9e1e3b56b7afd7778fbcd780bf657103c88f2170a601b9bf5 |
File details
Details for the file cykooz.resizer-1.0-cp310-cp310-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-1.0-cp310-cp310-macosx_10_7_x86_64.whl
- Upload date:
- Size: 219.7 kB
- Tags: CPython 3.10, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0661f345536d67c33c3106291cf360a0d16f31c2afd75c93a7746b8549a3ede |
|
MD5 | 3dcff1d09592551d1c022e299c37d527 |
|
BLAKE2b-256 | 9f7c0aa2945b9f840ba8af76c45b8ec66b2f91915baba7420a7c3684b02643ec |
File details
Details for the file cykooz.resizer-1.0-cp39-none-win_amd64.whl
.
File metadata
- Download URL: cykooz.resizer-1.0-cp39-none-win_amd64.whl
- Upload date:
- Size: 180.7 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f53498ead5a8391aa532ae6f550579e5e8eee5c6cf0928259ce49a19a433a63 |
|
MD5 | 80ed588f8884bf82c8411f3ba12aae6d |
|
BLAKE2b-256 | 5ab48bfacdc9af5e6f9e0288932d967dd4b57ce3aec23ddf04d2d61a7d539687 |
File details
Details for the file cykooz.resizer-1.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-1.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 221.7 kB
- Tags: CPython 3.9, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99427fd877a956122a3db60401c8bc94e5d49c55e6f84dd5ec54ef9bf5006eb1 |
|
MD5 | 34f6849f9650739a406833738b38d643 |
|
BLAKE2b-256 | 5d45dcb90e0d341fd5d85ce38c18004dae7d0edae3b45331e43bc989ed4f756d |
File details
Details for the file cykooz.resizer-1.0-cp39-cp39-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-1.0-cp39-cp39-macosx_10_7_x86_64.whl
- Upload date:
- Size: 219.7 kB
- Tags: CPython 3.9, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db70d754fd0f4bc80f4415ae4e6ef69275d9126ea0a3d3de75f4d19a64a14dd7 |
|
MD5 | acbfcd1de7a1e9e570f5f4e5d4595bde |
|
BLAKE2b-256 | f996a1b26ccba02b56d2b0d576964e74282c0d328954f650e87d772360c9f90a |
File details
Details for the file cykooz.resizer-1.0-cp38-none-win_amd64.whl
.
File metadata
- Download URL: cykooz.resizer-1.0-cp38-none-win_amd64.whl
- Upload date:
- Size: 180.8 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99a676f7fb165c0119949669922b97df0c1403f4530efe10072c4a0e70166d5b |
|
MD5 | 3659c3f7805828e61e2a7a440976faa2 |
|
BLAKE2b-256 | f07d7b96fd0cbef19cd486db013d92dcc5d851a4b831e55c30c91c287f9fea10 |
File details
Details for the file cykooz.resizer-1.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-1.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 221.8 kB
- Tags: CPython 3.8, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bf0370ff67d70a662250067fdde73491b9acdc53d1aca9ed568bdfc9d81954a |
|
MD5 | 0017e2f072d071fe1fe2c6395328cc16 |
|
BLAKE2b-256 | 8670213521bde30cbf9442f595051b4aabd3fb7a9875be6fded98f79bfb810cf |
File details
Details for the file cykooz.resizer-1.0-cp38-cp38-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-1.0-cp38-cp38-macosx_10_7_x86_64.whl
- Upload date:
- Size: 219.8 kB
- Tags: CPython 3.8, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 734b9098d6956f0a991d879a0378a05e80be83dc3ba4e7fc0da53e998d572db3 |
|
MD5 | 09d80b610c9e66611c13410e03844443 |
|
BLAKE2b-256 | d46dfa3f105b752478aad1366bb835584fabb62859d3a71a655b2830a268e628 |
File details
Details for the file cykooz.resizer-1.0-cp37-none-win_amd64.whl
.
File metadata
- Download URL: cykooz.resizer-1.0-cp37-none-win_amd64.whl
- Upload date:
- Size: 180.8 kB
- Tags: CPython 3.7, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee328cb615a2ade687d770dbff98c0a42ae795ab60639f466f4ff9e703faf84f |
|
MD5 | 1b28bad34b1c23bf3b680507428d74d2 |
|
BLAKE2b-256 | 46c9cfd83fff48e83c4a29772b9583dd770713f7e4cfb65d313b63772ef83c2e |
File details
Details for the file cykooz.resizer-1.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-1.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 221.8 kB
- Tags: CPython 3.7m, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dd1f7f9106e41895a36b3ca070e68092418fa739630a11fb9bd08bf6a390949 |
|
MD5 | aba2af1d783bfbfe0aac03cc72b74a47 |
|
BLAKE2b-256 | 6d3f7d163eb089cbaf9706e793430758e2714463f7ed7db0f49175aed4f08635 |
File details
Details for the file cykooz.resizer-1.0-cp37-cp37m-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-1.0-cp37-cp37m-macosx_10_7_x86_64.whl
- Upload date:
- Size: 219.8 kB
- Tags: CPython 3.7m, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 828418553a102427c99ebb8e06b6f03a01c19394287cf6ec0186363038f22535 |
|
MD5 | fbfda7e1f9d2389480a5b7b3f4f44ed3 |
|
BLAKE2b-256 | 2be376d4d926cfe3658ed267c8a10580f51329489e5a026df6870e99d509bc30 |
File details
Details for the file cykooz.resizer-1.0-cp36-none-win_amd64.whl
.
File metadata
- Download URL: cykooz.resizer-1.0-cp36-none-win_amd64.whl
- Upload date:
- Size: 177.1 kB
- Tags: CPython 3.6, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a87dd3e8fb24bb3d753a6918f8cfa4773318962f2b501cf6ae742ebf7bf4b782 |
|
MD5 | 3e7fbd725ca4ad980736560535fc88bd |
|
BLAKE2b-256 | 914e22c158916f5fab85c388b31d1146f56232365d9d565e7cf9c5cc73a4cce0 |
File details
Details for the file cykooz.resizer-1.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-1.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 219.9 kB
- Tags: CPython 3.6m, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 822d8a2ef892168e26a0e0d6c402dcdd415182f847fb36a5e9e489761720aa2a |
|
MD5 | f48b34cdd0e9960b0da59038bf20724a |
|
BLAKE2b-256 | 4dcefc97e6e1581eac9aa997ea08fde2f1fbf09c7638ff23249a148fb3a1d02f |
File details
Details for the file cykooz.resizer-1.0-cp36-cp36m-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-1.0-cp36-cp36m-macosx_10_7_x86_64.whl
- Upload date:
- Size: 218.2 kB
- Tags: CPython 3.6m, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e119353a891d4d4d20267e13e3355d69415db9098ce5d8cdb92224aeee7234e6 |
|
MD5 | 896739d8ce6ecae2a3fc74828b42c71b |
|
BLAKE2b-256 | 9771b92ab11f754841d79962a60b06ff24a858da0c08dcb1d1a204bc24069361 |