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:
Format | Description | Native Rust | SSE4.1 | AVX2 |
---|---|---|---|---|
U8 | One u8 component per pixel (e.g. L) |
+ | partial | + |
U8x2 | Two u8 components per pixel (e.g. LA) |
+ | + | + |
U8x3 | Three u8 components per pixel (e.g. RGB) |
+ | partial | + |
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 - 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: AMD Ryzen 9 5950X
- RAM: DDR4 3800 MHz
- Ubuntu 22.04 (linux 5.15.0)
- Python 3.9
- Rust 1.62.0
- cykooz.resizer = "2.1"
Other Python libraries used to compare of resizing speed:
- Pillow = "9.2.0" (https://pypi-hypernode.com/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.66 | 93.16 | 179.96 |
cykooz.resizer | 0.20 | 39.19 | 76.71 |
cykooz.resizer - sse4_1 | 0.20 | 15.60 | 25.16 |
cykooz.resizer - avx2 | 0.20 | 11.95 | 18.54 |
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.28 | 20.73 | 51.07 |
cykooz.resizer | 0.19 | 14.31 | 23.84 |
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.1.1.tar.gz
.
File metadata
- Download URL: cykooz.resizer-2.1.1.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff16a0913a3fdfe3e5250b626bfcc02568d8d7051ebd1108882d8cca2a7af634 |
|
MD5 | 7b7880fafafcb625c822f1df82f024da |
|
BLAKE2b-256 | 8c40dc016b1488a6b62c50c221fae68e4408a1b8889d013b3f0fef1f4035d16a |
File details
Details for the file cykooz.resizer-2.1.1-cp310-none-win_amd64.whl
.
File metadata
- Download URL: cykooz.resizer-2.1.1-cp310-none-win_amd64.whl
- Upload date:
- Size: 515.7 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d812649892f0fac1b70ff392992a48c20ca9d12b7fd1ca8cfaed5f26011a2c65 |
|
MD5 | 1519ddc5b337046aac54255b81ca6765 |
|
BLAKE2b-256 | 00e921c6147c5e42a3a1ea425560aafaa08e78d9f61bb42102a1ef7e276ef3f0 |
File details
Details for the file cykooz.resizer-2.1.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-2.1.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 567.1 kB
- Tags: CPython 3.10, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35ab931f38d747fbb90c814f65c931d2b30ff7fbaa2659183738a5b66cf3a830 |
|
MD5 | 26c6c5b6599e230a60c201733542365d |
|
BLAKE2b-256 | 6c51054d9ae11cb43d70315bca702c8b7e081307edf645bd86108deb2fc3cec0 |
File details
Details for the file cykooz.resizer-2.1.1-cp310-cp310-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-2.1.1-cp310-cp310-macosx_10_7_x86_64.whl
- Upload date:
- Size: 555.0 kB
- Tags: CPython 3.10, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f24abdfd54a73d009a3f2ee8aebd41929a993c071e506ca1fd4d4a1f53017153 |
|
MD5 | 3921ab180131ba2913c9726ea881f682 |
|
BLAKE2b-256 | 59a987b257f4758650939838fe0f497eb8d5ee3407a8cf85c86acfdfc757aa48 |
File details
Details for the file cykooz.resizer-2.1.1-cp39-none-win_amd64.whl
.
File metadata
- Download URL: cykooz.resizer-2.1.1-cp39-none-win_amd64.whl
- Upload date:
- Size: 515.7 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ca7a3ac597579e8e414db6d9463d9b64c45d7945a02c17947fb79607f2b719c |
|
MD5 | 4cb64eec29c7f13d194a9b69c9e86db9 |
|
BLAKE2b-256 | c8c3521958ee0ac1a3b7c0cce46b3bb6524628cad0e51aeadb4a861ef581fdec |
File details
Details for the file cykooz.resizer-2.1.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-2.1.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 567.1 kB
- Tags: CPython 3.9, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c22d6a5d8d0b40a96b07c1d2c52606383b228dfd67165bbd7a53c66a426ae508 |
|
MD5 | ac971f79c1d285b5ddd879c63e817f56 |
|
BLAKE2b-256 | f984ee6e8a9bcc873dc0ee116ef9b64fb232991e713541984fd48ea3ca89e38e |
File details
Details for the file cykooz.resizer-2.1.1-cp39-cp39-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-2.1.1-cp39-cp39-macosx_10_7_x86_64.whl
- Upload date:
- Size: 555.0 kB
- Tags: CPython 3.9, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d72c5700c183a9a99eabe59aacb76059b59af19988d95c3ba228cfea08303657 |
|
MD5 | fb7dc48bbda700a64389f3415207419a |
|
BLAKE2b-256 | ebecabba198866b0526dff756436c8c643a4186aab0736459027d0679eb34c6f |
File details
Details for the file cykooz.resizer-2.1.1-cp38-none-win_amd64.whl
.
File metadata
- Download URL: cykooz.resizer-2.1.1-cp38-none-win_amd64.whl
- Upload date:
- Size: 516.1 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be239d47e54a6c4a3f91a8e66ac34a0c9adb4625faf22a1d3714ac7580c7097a |
|
MD5 | c2bd32ecf8c522db7d3dcdac453973f7 |
|
BLAKE2b-256 | c5baefe9bbc7753a5808c39d8e56a2fea489270f453ac064a071f44288e7d3a5 |
File details
Details for the file cykooz.resizer-2.1.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-2.1.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 567.3 kB
- Tags: CPython 3.8, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f280d228fdc9bafb878168d5fb92c850d68a633208a681a95e48bb4484f32ad |
|
MD5 | 33fe8842719e8c5ce3e58ecdbc8ccd58 |
|
BLAKE2b-256 | 3e1f6575202aaa501f2918ab77fb189576dea7b6521114ea0598fd146a2bf911 |
File details
Details for the file cykooz.resizer-2.1.1-cp38-cp38-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-2.1.1-cp38-cp38-macosx_10_7_x86_64.whl
- Upload date:
- Size: 555.3 kB
- Tags: CPython 3.8, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb269e5d8dc0b19e7cdf539ccccca4cf42792c910c89cddbd00d36ba503b406a |
|
MD5 | beb29e4db2463124c8664a98f071d209 |
|
BLAKE2b-256 | 5dc467667a027bf944c878bc20b4205f202b5640ec9eb4e5218966fbbd325640 |
File details
Details for the file cykooz.resizer-2.1.1-cp37-none-win_amd64.whl
.
File metadata
- Download URL: cykooz.resizer-2.1.1-cp37-none-win_amd64.whl
- Upload date:
- Size: 516.1 kB
- Tags: CPython 3.7, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d77cacf6b751f7aff6d18416fe25b2c8d2e98ba0b7a3e1e8a57a1e7318761297 |
|
MD5 | f08d08055612eb7f093abe5ac7f04afd |
|
BLAKE2b-256 | 79e879f3c529b6733cc60082572dd0bf0a6ff0c82c77db5df651835ae05f41c3 |
File details
Details for the file cykooz.resizer-2.1.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-2.1.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 567.3 kB
- Tags: CPython 3.7m, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d635f84029b00fc8a9b3faa47982032bfcf379871b1c58bbb3bbdab64e009f4 |
|
MD5 | 79bdb5f9db613ee3469eb5b826671bda |
|
BLAKE2b-256 | 92302dd78f19bcb4e454a865cc8040a572f97d57b2b779f2eddefa83ebe6f699 |
File details
Details for the file cykooz.resizer-2.1.1-cp37-cp37m-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: cykooz.resizer-2.1.1-cp37-cp37m-macosx_10_7_x86_64.whl
- Upload date:
- Size: 555.3 kB
- Tags: CPython 3.7m, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2856def8e2238536d851736d2c60e375ab8b494ef9563569e6cbe5ee3c5dd20 |
|
MD5 | 4805fe27de944ab0d8afb0ae3e5965a3 |
|
BLAKE2b-256 | e8d554792f58c7702f0ec2b3ad158c7892b0a3f44aeed7810bea478416433d22 |