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
U8
- one byte 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.9
- Rust 1.56
- cykooz.resizer = "1.1"
Other Python libraries used to compare of resizing speed:
- Pillow = "8.4.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.92 | 99.39 | 230.47 |
cykooz.resizer | 0.51 | 68.74 | 126.34 |
cykooz.resizer - sse4_1 | 0.51 | 25.90 | 39.40 |
cykooz.resizer - avx2 | 0.51 | 17.99 | 28.40 |
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 | 0.33 | 39.52 | 118.68 |
cykooz.resizer | 0.21 | 25.82 | 49.49 |
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.1.tar.gz
.
File metadata
- Download URL: cykooz.resizer-1.1.tar.gz
- Upload date:
- Size: 17.0 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.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff6805eabc9bab4cea4d0468eea81d749bdd5bee8b2b71641925c5ba66ab21a0 |
|
MD5 | 84ad78019a3a78a7b04780c28085c7cb |
|
BLAKE2b-256 | 8de6aa58664461bc2a2e7ff07eb49fac041ddffd5b2565352fdb3c3ac5694816 |
File details
Details for the file cykooz.resizer-1.1-cp310-none-win_amd64.whl
.
File metadata
- Download URL: cykooz.resizer-1.1-cp310-none-win_amd64.whl
- Upload date:
- Size: 190.4 kB
- Tags: CPython 3.10, 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.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce1d359920dc4dddd74e24f6281a544bd02acdb7f745efdbccf37798b25b93c1 |
|
MD5 | e760d9227e55730f8f27a51d66500def |
|
BLAKE2b-256 | 4c0778140ca3603a8aafd7f7f89787513e183426aff1fa8643a27b854506eb89 |
File details
Details for the file cykooz.resizer-1.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-1.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 247.1 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.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67ba3efb723fadc4e6b0c1762cf5b6226e69cdccafcd8ffd395e26f60a19702f |
|
MD5 | ce0b7485615bdb795c041b8090f66028 |
|
BLAKE2b-256 | 424b6bb12124aacee2ee602bfaa21feded948a77e837c86b37b914980c0a95ce |
File details
Details for the file cykooz.resizer-1.1-cp310-cp310-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-1.1-cp310-cp310-macosx_10_7_x86_64.whl
- Upload date:
- Size: 237.2 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.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58bc720e1794c076fafb70567bd0b7683307f7560f2894a5a905d52123464262 |
|
MD5 | fca1340132677a7a718b04de07651642 |
|
BLAKE2b-256 | f41dc43c49965465856b795cdecea5aa794e36d102628b599a9ffbbcbbd15f91 |
File details
Details for the file cykooz.resizer-1.1-cp39-none-win_amd64.whl
.
File metadata
- Download URL: cykooz.resizer-1.1-cp39-none-win_amd64.whl
- Upload date:
- Size: 190.4 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.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 586b51addb30a77accb1c07f9b09c9fc2a4ee7028d96fa2a3ad353820dd981d8 |
|
MD5 | 953972b26e4e01a2fc22e2178900de3f |
|
BLAKE2b-256 | 097e573b03902d3c16edebc94e391ffb5a9d42cde7be5c44f380c4ce0e7a524a |
File details
Details for the file cykooz.resizer-1.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-1.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 247.1 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.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4d5d253c99a58d30ec244ea4556a377709b662fe355a4560f25b500d128c637 |
|
MD5 | 9bbd5ecfa59ec9ab2474ae19b8a20835 |
|
BLAKE2b-256 | f027ce230ae67c97e3415163d7011c91979139ea2f4248c9d9b0c3787439d4f7 |
File details
Details for the file cykooz.resizer-1.1-cp39-cp39-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-1.1-cp39-cp39-macosx_10_7_x86_64.whl
- Upload date:
- Size: 237.2 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.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5f427eac1e459ecc2f96160346db1b91bebca933e5db2bfae48118167e8c2e7 |
|
MD5 | bc4d7b93297fb0dcec265f235c5f6612 |
|
BLAKE2b-256 | b1c10beb432fc89425d5dce48f2d1085c0e6e8c58b488d0eb3235461dc28c605 |
File details
Details for the file cykooz.resizer-1.1-cp38-none-win_amd64.whl
.
File metadata
- Download URL: cykooz.resizer-1.1-cp38-none-win_amd64.whl
- Upload date:
- Size: 190.7 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.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3f1a6d6b6535c836123bfcc792ef0db9e18f881f068202614d5b50507c93782 |
|
MD5 | ea94c02dfa4e382eb4aabc89766bbcb1 |
|
BLAKE2b-256 | f38533773165b2e5c944a4a5826f0dcf8a9f848e42e021fbf5e9f35d22b847c9 |
File details
Details for the file cykooz.resizer-1.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-1.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 247.2 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.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a17195b77e2e1e0e5bf3a558a83c224b96d87e72bbe5c97693c88be853505df |
|
MD5 | aee6a61ff05b4538559a371be95421b5 |
|
BLAKE2b-256 | f1cad184348f1d88e722c15ea49979c946a9f0e1da485806b75206e4865f432b |
File details
Details for the file cykooz.resizer-1.1-cp38-cp38-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-1.1-cp38-cp38-macosx_10_7_x86_64.whl
- Upload date:
- Size: 237.3 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.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2628d24e2cf93d2d5d6a6cb82efe41e763683a08cab6b98f09a14986a9aa71b |
|
MD5 | ef355c2650b2560321bc8a7bd5cf7178 |
|
BLAKE2b-256 | 1ffc087711f4e81ad0987e8990d19c411d8247b64cec0eedb110c768cf8c722b |
File details
Details for the file cykooz.resizer-1.1-cp37-none-win_amd64.whl
.
File metadata
- Download URL: cykooz.resizer-1.1-cp37-none-win_amd64.whl
- Upload date:
- Size: 190.7 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.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75b97882459a4463878966c8613114b64bd2fb1465b9faa9f75c26e8af5ba98e |
|
MD5 | 97c02d4ac396f6b107a31bee6c5fddbf |
|
BLAKE2b-256 | 58266475b82796f7bf3be8d27653e0c7ac6b7e0630461526da902d4946c5e904 |
File details
Details for the file cykooz.resizer-1.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-1.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 247.2 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.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5018b91df64f3511a9209a8d863f78ba1566cc772eb3ec65f4ef71887a2178b5 |
|
MD5 | dc2da2725ca010655b9ee87e18602273 |
|
BLAKE2b-256 | 4a8dfe14c9426a558c41f0ee9cac1cce9f0785bbc65546b97aff1a947e8c0a6b |
File details
Details for the file cykooz.resizer-1.1-cp37-cp37m-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-1.1-cp37-cp37m-macosx_10_7_x86_64.whl
- Upload date:
- Size: 237.3 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.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e23f0c77b528401003e4074742e4e012b76257ccadc014c23785b9398523039c |
|
MD5 | 74e8f8817edd3192a68b473dee12091b |
|
BLAKE2b-256 | 1e480e976c38f047a69b2fe8673d8c7a3c6258a21a27bd54d83b4b98d9ea2103 |
File details
Details for the file cykooz.resizer-1.1-cp36-none-win_amd64.whl
.
File metadata
- Download URL: cykooz.resizer-1.1-cp36-none-win_amd64.whl
- Upload date:
- Size: 187.9 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.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af79ee98b96c0eb3a1260a8a4848db38ff54e3095949b8a1ff15566b4c579f90 |
|
MD5 | f6b93cab251ba39f5d3e40a77643b167 |
|
BLAKE2b-256 | d21de17cb9285cb385ff8dc2c193aebf9c206ac7d3ab52e19de9be9ee968ccae |
File details
Details for the file cykooz.resizer-1.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-1.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 244.3 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.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf9dcaf61acce6278fdb79f0a7158533139525c4785407b6b5930a30bbc12e8f |
|
MD5 | 76561740dc1324cd8605eed2462e23f8 |
|
BLAKE2b-256 | 1072cc363a832dd6a816c18758249671a17e0967c07451b08ddf24634a05120d |
File details
Details for the file cykooz.resizer-1.1-cp36-cp36m-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-1.1-cp36-cp36m-macosx_10_7_x86_64.whl
- Upload date:
- Size: 233.0 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.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 847bf23f157107db0b1bd35e20b5993fd0e160523ae8892b8af5cc16ed92b2c0 |
|
MD5 | 557dba14f898cbe98931e5ea829ca48d |
|
BLAKE2b-256 | bcf01d5d7586f4000dc2d828c4f43c579a8984875750a47167445bdda8a09bb0 |