A fast image resizer
Project description
cykooz.resizer
cykooz.resizer
is package with the 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:
Format | Description | SSE4.1 | AVX2 | Neon |
---|---|---|---|---|
U8 | One u8 component per pixel (e.g. L) |
+ | + | + |
U8x2 | Two u8 components per pixel (e.g. LA) |
+ | + | + |
U8x3 | Three u8 components per pixel (e.g. RGB) |
+ | + | + |
U8x4 | Four u8 components per pixel (e.g. RGBA, RGBx, CMYK) |
+ | + | + |
U16 | One u16 components per pixel (e.g. L16) |
+ | + | + |
U16x2 | Two u16 components per pixel (e.g. LA16) |
+ | + | + |
U16x3 | Three u16 components per pixel (e.g. RGB16) |
+ | + | + |
U16x4 | Four u16 components per pixel (e.g. RGBA16, RGBx16, CMYK16) |
+ | + | + |
I32 | One i32 component per pixel |
- | - | - |
F32 | One f32 component per pixel |
- | - | - |
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 - is resizing an image in two steps. The first step uses the "nearest" algorithm. The 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 an 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: AMD Ryzen 9 5950X
- RAM: DDR4 3800 MHz
- Ubuntu 22.04 (linux 6.5.0)
- Python 3.10
- Rust 1.75.0
- cykooz.resizer = "2.2"
Other Python libraries used to compare of resizing speed:
- Pillow = "10.2.0" (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.88 | 105.27 | 200.80 |
cykooz.resizer | 0.20 | 29.64 | 58.83 |
cykooz.resizer - sse4_1 | 0.20 | 14.83 | 27.87 |
cykooz.resizer - avx2 | 0.20 | 10.44 | 21.34 |
Resize grayscale (U8) image 4928x3279 => 852x567
- Source image nasa-4928x3279.png has converted into grayscale image with one byte per pixel.
Package (time in ms) | nearest | bilinear | lanczos3 |
---|---|---|---|
Pillow U8 | 0.27 | 23.78 | 61.23 |
cykooz.resizer U8 | 0.17 | 5.29 | 11.44 |
cykooz.resizer U8 - sse4_1 | 0.17 | 2.30 | 5.90 |
cykooz.resizer U8 - avx2 | 0.17 | 1.85 | 4.17 |
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-2.2.1.tar.gz
.
File metadata
- Download URL: cykooz.resizer-2.2.1.tar.gz
- Upload date:
- Size: 13.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfe45dd054bf402700880b19532c049f286bba79881c6131bc04187b18a14aa0 |
|
MD5 | 09fcba74eb4e415ecf7d1cbaae923354 |
|
BLAKE2b-256 | a26e72a817190daae9d4bab1b3fd265bddcfd7c9d4b7ea1d33309c331c967a82 |
File details
Details for the file cykooz.resizer-2.2.1-cp312-none-win_amd64.whl
.
File metadata
- Download URL: cykooz.resizer-2.2.1-cp312-none-win_amd64.whl
- Upload date:
- Size: 611.3 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb58cfa72c91a967ecbaf13e41db1bc185b8df0b799743687fed2b73a82d94a8 |
|
MD5 | 3b903782a9588b69ca98501a4557559d |
|
BLAKE2b-256 | 613d2259b022782451cd49b10344784e4ba3fd43e58bb453fcdc661f589273dc |
File details
Details for the file cykooz.resizer-2.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-2.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 672.5 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b752d118c66b9460e9826add7f1063bb3cf9561ffa96e1a87f5deb24b4e6301 |
|
MD5 | e8a905229592bd986779ec388a7f9c62 |
|
BLAKE2b-256 | 28659c0bd2d4dddee8887f5f00abd4e8e4ae6b9782ba54ade9845be4d12e00af |
File details
Details for the file cykooz.resizer-2.2.1-cp312-cp312-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-2.2.1-cp312-cp312-macosx_10_12_x86_64.whl
- Upload date:
- Size: 666.5 kB
- Tags: CPython 3.12, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a1b714f54f83997f57e427607a496afa0cf2274c4af7a2bdca707ed9aa557b4 |
|
MD5 | 0ee3dd7373b173e36d44ca7cc1d6a7fd |
|
BLAKE2b-256 | 0164c89c84c6812efca5b3cdfd62d135f698da3d3312be17563779657c16e5e2 |
File details
Details for the file cykooz.resizer-2.2.1-cp311-none-win_amd64.whl
.
File metadata
- Download URL: cykooz.resizer-2.2.1-cp311-none-win_amd64.whl
- Upload date:
- Size: 610.7 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4e4686287075568253ffad2634c613efc00c6b5315c79865b5920194d7d106a |
|
MD5 | 65457bfaf3b92644910952c40411b301 |
|
BLAKE2b-256 | 821a0aa542bc56194337130b928a05a6855369eab024369e69a343fd9ab7ffd9 |
File details
Details for the file cykooz.resizer-2.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-2.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 672.8 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c0cdf71f93229f77e9439c0a1bafc64a980f86fb433a0781671a95f10304e4f |
|
MD5 | efcb2f0adcf8aad17b4189004a22e5dc |
|
BLAKE2b-256 | 174f4679a439696f2995af2b215dead6c9b5d76c4f56519a50449b3652da08e2 |
File details
Details for the file cykooz.resizer-2.2.1-cp311-cp311-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-2.2.1-cp311-cp311-macosx_10_12_x86_64.whl
- Upload date:
- Size: 667.2 kB
- Tags: CPython 3.11, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95a7fac2beeab7d489cf458579e9b93d39113026855153e71fc6e854f6fd422d |
|
MD5 | aa802dd506373076ebe1e5403b5f4608 |
|
BLAKE2b-256 | d3405b9bd3c54f4a9b3788243b86a0fcb2b23636a03c24799a13adb9e64d1451 |
File details
Details for the file cykooz.resizer-2.2.1-cp310-none-win_amd64.whl
.
File metadata
- Download URL: cykooz.resizer-2.2.1-cp310-none-win_amd64.whl
- Upload date:
- Size: 610.7 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b5ed6eafcce0e43505b1dab26b2152cbbf52db323a159b9f5f4a5fb503f780c |
|
MD5 | 0df134f1082d51606191e4959fe09380 |
|
BLAKE2b-256 | 8cfd16e16bd5564e39781c65315ca698e433249127b291a21d57608aec1e6c92 |
File details
Details for the file cykooz.resizer-2.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-2.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 672.8 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e7da4d38c696cf60662322c665852eadfaf987a6c06a13458a29e331c3198bf |
|
MD5 | aae40327d1dfed34262186e8764f2099 |
|
BLAKE2b-256 | 7f153f65fabd970e2d08c7b2dcd9d449c94a5ff94107ce830caef55859a39aa6 |
File details
Details for the file cykooz.resizer-2.2.1-cp310-cp310-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-2.2.1-cp310-cp310-macosx_10_12_x86_64.whl
- Upload date:
- Size: 667.2 kB
- Tags: CPython 3.10, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee48570b86fc58180db4a39bd2814dc040a821fef47253d4304f8dcd2b2a64d6 |
|
MD5 | 1c81b7f14469c3ed0473c28be4572561 |
|
BLAKE2b-256 | a9f19975a158b247c17cf2047efc4101deb16cd1c4fdc608e3885b617fabfa40 |
File details
Details for the file cykooz.resizer-2.2.1-cp39-none-win_amd64.whl
.
File metadata
- Download URL: cykooz.resizer-2.2.1-cp39-none-win_amd64.whl
- Upload date:
- Size: 610.9 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbd09497aa07d2cf9ae410a20f1d9939c9845be65b56f29aa6069815aef962be |
|
MD5 | 5ec7d724e569c41bbebcebdc95ed0d7d |
|
BLAKE2b-256 | 92df18859cc8ead936a468208dd82ca3056f4bc7383b8439265e0a1e0737cf1a |
File details
Details for the file cykooz.resizer-2.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-2.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 673.2 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 554ca21700d938bcbec5b379afe5c7b0f2aeb8d89562e8a3898e0b4a65097b3d |
|
MD5 | 06aa733993c1feadfb671b20b6e857be |
|
BLAKE2b-256 | 8773dbd10b771418657baeb1cc4090f975dd8c925b1f713b6c661279afa7fb5e |
File details
Details for the file cykooz.resizer-2.2.1-cp39-cp39-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-2.2.1-cp39-cp39-macosx_10_12_x86_64.whl
- Upload date:
- Size: 667.4 kB
- Tags: CPython 3.9, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1034636e59d44c87d1045c2e86ea07ddf194cf05fc32bdd7b99c6c87ae7e6650 |
|
MD5 | 14933dab40fe7993920aa5e882b114af |
|
BLAKE2b-256 | 9176978e2ee9a6322d34991a9f7a8c6ecb3b6ac71d23eeac17dcbc3fdaacfae8 |
File details
Details for the file cykooz.resizer-2.2.1-cp38-none-win_amd64.whl
.
File metadata
- Download URL: cykooz.resizer-2.2.1-cp38-none-win_amd64.whl
- Upload date:
- Size: 611.1 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 964ae3bed1d9d71b963db1dc7384f63f07cd7d69ca7de62ba6d2b996573702d9 |
|
MD5 | 5f6df7ebf9928ecee7bd001075210114 |
|
BLAKE2b-256 | 46697b616b288ddf5e29fc5987989d5389623c53b1dffee5d2ab6f6be6a956fa |
File details
Details for the file cykooz.resizer-2.2.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-2.2.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 673.3 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc3dd3bba97567ec456c148ea1d8a60b2b5562e8249efe493b3ad049ad2d9e53 |
|
MD5 | 266b6a157298b1c2253d919fe7c1cbe0 |
|
BLAKE2b-256 | a6f40badb75ab8f0f2d38412c1786b0347dfb75eba2d255b6c134724972d582f |
File details
Details for the file cykooz.resizer-2.2.1-cp38-cp38-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-2.2.1-cp38-cp38-macosx_10_12_x86_64.whl
- Upload date:
- Size: 667.6 kB
- Tags: CPython 3.8, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07f8cfb7e6d01ab377a3388fac088beed6e916be1d1d92297345d76361eea004 |
|
MD5 | baede29d74214c1ea5c5f16bfdc8d601 |
|
BLAKE2b-256 | dd22513f69e161f5111b78d34b774b8e54b65a6d452ef4853ac94b876c503259 |
File details
Details for the file cykooz.resizer-2.2.1-cp37-none-win_amd64.whl
.
File metadata
- Download URL: cykooz.resizer-2.2.1-cp37-none-win_amd64.whl
- Upload date:
- Size: 611.1 kB
- Tags: CPython 3.7, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 341b8e6fc0c62a79b6bfa923af9738356ecf190f9d5f0ce3c65829220e5e2b98 |
|
MD5 | aa64f3b2fc5c5e897ea0f45db1a835df |
|
BLAKE2b-256 | 9ccbdba9918960aea7ec9de25c04407a4455b4f601369f5400240f0f8c83a259 |
File details
Details for the file cykooz.resizer-2.2.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-2.2.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 673.4 kB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e22116c92b8366b0b4a475c9852172467dc41cc9eae1f5cf65aad95b0c8e501 |
|
MD5 | 0e3aab929ee4ba61fe3a92023a99e11b |
|
BLAKE2b-256 | 3cd0d73ea051824602ff7fd30e2be5e4c9a4bc664246541575d478367b107de6 |
File details
Details for the file cykooz.resizer-2.2.1-cp37-cp37m-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-2.2.1-cp37-cp37m-macosx_10_12_x86_64.whl
- Upload date:
- Size: 667.7 kB
- Tags: CPython 3.7m, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97b0cf6c492be80d020959ed6f9e867b3731c4dfe316fa89b9e02f0cf071933e |
|
MD5 | d7e32aae43d14713a94620bb35cca38c |
|
BLAKE2b-256 | af19f7e5533065ed42f8f29df0cb0fe8ae4cea9d045a6c2f74a0e850edf7de31 |