Skip to main content

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.

CHANGELOG

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:

Resize algorithms:

  • Nearest
  • Convolution with Bilinear filter
  • Convolution with Lanczos3 filter

Resize RGBA image 4928x3279 => 852x567

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

cykooz.resizer-2.2.0.tar.gz (13.4 MB view details)

Uploaded Source

Built Distributions

cykooz.resizer-2.2.0-cp312-none-win_amd64.whl (615.4 kB view details)

Uploaded CPython 3.12 Windows x86-64

cykooz.resizer-2.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (684.4 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

cykooz.resizer-2.2.0-cp312-cp312-macosx_10_12_x86_64.whl (667.0 kB view details)

Uploaded CPython 3.12 macOS 10.12+ x86-64

cykooz.resizer-2.2.0-cp311-none-win_amd64.whl (614.8 kB view details)

Uploaded CPython 3.11 Windows x86-64

cykooz.resizer-2.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (684.8 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

cykooz.resizer-2.2.0-cp311-cp311-macosx_10_12_x86_64.whl (667.7 kB view details)

Uploaded CPython 3.11 macOS 10.12+ x86-64

cykooz.resizer-2.2.0-cp310-none-win_amd64.whl (614.8 kB view details)

Uploaded CPython 3.10 Windows x86-64

cykooz.resizer-2.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (684.7 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

cykooz.resizer-2.2.0-cp310-cp310-macosx_10_12_x86_64.whl (667.7 kB view details)

Uploaded CPython 3.10 macOS 10.12+ x86-64

cykooz.resizer-2.2.0-cp39-none-win_amd64.whl (615.1 kB view details)

Uploaded CPython 3.9 Windows x86-64

cykooz.resizer-2.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (685.0 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

cykooz.resizer-2.2.0-cp39-cp39-macosx_10_12_x86_64.whl (667.9 kB view details)

Uploaded CPython 3.9 macOS 10.12+ x86-64

cykooz.resizer-2.2.0-cp38-none-win_amd64.whl (615.0 kB view details)

Uploaded CPython 3.8 Windows x86-64

cykooz.resizer-2.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (685.0 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

cykooz.resizer-2.2.0-cp38-cp38-macosx_10_12_x86_64.whl (667.9 kB view details)

Uploaded CPython 3.8 macOS 10.12+ x86-64

cykooz.resizer-2.2.0-cp37-none-win_amd64.whl (615.0 kB view details)

Uploaded CPython 3.7 Windows x86-64

cykooz.resizer-2.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (685.0 kB view details)

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

cykooz.resizer-2.2.0-cp37-cp37m-macosx_10_12_x86_64.whl (668.0 kB view details)

Uploaded CPython 3.7m macOS 10.12+ x86-64

File details

Details for the file cykooz.resizer-2.2.0.tar.gz.

File metadata

  • Download URL: cykooz.resizer-2.2.0.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

Hashes for cykooz.resizer-2.2.0.tar.gz
Algorithm Hash digest
SHA256 b740345eddb94717684a4476964f0e97c1ab7b3ae5d4d2055f46ce1401f6fbf3
MD5 30bdb6886147ebd283c9104de942c9a3
BLAKE2b-256 22f010d4c57a866015ce80d08b5732365d1b667b32348d5517524a31edfbcd77

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.2.0-cp312-none-win_amd64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.2.0-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 8b12ca2c9d24d790fc7f1bb6a13c717d3fa5c80d2479e845b9c4b9e8dc6ccc5b
MD5 a896b260dc0d2c5fc4dff573092b6556
BLAKE2b-256 3cb1ad220eac5bc882212839671dca307420f879795aff963c4df2a8f6f81474

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 400e95d45b858b2997e6abf0d8e3739bb8b8fce1842d2161f48b6564f2dbf6fe
MD5 909a46079460f1eb56ff02e9ae805167
BLAKE2b-256 198588bde3e6b1f1c1eb6f359e60c61b02c3d1fcdaa4f2096139d11cd8369b02

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.2.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.2.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 82247c7a7a95f6ddfea566b75555c3b05c2dbb32b192ed99a7e73f897d1f421a
MD5 5f932fd3b0f339dc7aa04ffa82597b17
BLAKE2b-256 c3578434be8eeb5125ddc4be04de6860a2d51533ebffb57bb979b3d899b7dbed

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.2.0-cp311-none-win_amd64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.2.0-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 ba756a96a773490e9444a60f81e7959b3a5db7eff63d5c18aa926b2ef91c31a2
MD5 837e31a1542f082570ab0518ea8bdc1c
BLAKE2b-256 c42a7dc2ecb129659609c45c3999caa3b17a21e4e063d645c33d1659bd463452

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5881323b22b8a0a10ade4ffaff10ecbb1b568a923bc88e243cfe641733dc998b
MD5 184b9b61b8b6480c86c21017c8412a33
BLAKE2b-256 14ad9d61babb21a54a87014cb5fa6add1e9a184dc5ba57537b351d7a17b03faa

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.2.0-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.2.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 133be567de9fb3edb011a45815a6859e31f74db2a664c8d900d4008568381f42
MD5 63edd2347c6597f179da36ccca1cbe84
BLAKE2b-256 05a40abdba158e3c9cd96776b3a4568cee5bc9ec3fd401e125dc87f1b0fdcc68

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.2.0-cp310-none-win_amd64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.2.0-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 fc04c7fa7cf6d2876934c7ad1e01cb823160e6ff59611a3da6c6445f20b7ee63
MD5 2ae03ec80c04235350247256e40fcb54
BLAKE2b-256 f2a3ee60d67186b350a7e74c158824fe5e9de535f2e7bce3535e52b19a53c16b

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4a6fbe2c3bbeb7b757b4eade5affeeac738cdb605ab6b853055d098070041720
MD5 31876ed46cfd5d0421ad697d94a122d1
BLAKE2b-256 18965f45eb32922fc5e33322c8a21c0f03dbca88405e296b8857c93cb17a2431

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.2.0-cp310-cp310-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.2.0-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 2ddefc600b12c0983ec63e4da7178c1095042379d5b39df26e677c691dbaff62
MD5 652e857639f4ae218d9d0e4bff0cc12f
BLAKE2b-256 cab369cbebb0bfcd28b0dffcf142e7d25d69abd38947124ce51a3e40e9389ec7

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.2.0-cp39-none-win_amd64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.2.0-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 add5713c59eb9c0821bf4ee2de6ad1546096f15a1386a208b1423fe29bd976b3
MD5 266db5cf9cb473f4cad37058537bb5da
BLAKE2b-256 b939a7ce3e860fd00994a0bb2b8adbceab7ff7f2e52359d7431d102993bd6878

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8d2b54499687b0cd0e6620690b98d807dec50f8a9d93223336d6a0968d7bbe94
MD5 7bd50cc1cb66f861bc115ac13b377e30
BLAKE2b-256 fd0d2cd98eeeb30a4b42ed058146bb40008f04f9301191b6c393afd74e76746d

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.2.0-cp39-cp39-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.2.0-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 208f4caed6139f0b8997d2f0bc3c26a67e9a94dff4d1ad849581201fb2bd7831
MD5 747fff9a6739498dac7a3a019bbbf6d9
BLAKE2b-256 bbedaa0f9207ec9219dcbfa9874e2cad88be424e36af2c7db7286b874da97927

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.2.0-cp38-none-win_amd64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.2.0-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 bdf7acc5725acf7f189a3456d48f147890fb8ef2c528e9fa5cf63d77861cfa49
MD5 18be43eec1fe1a1eaaa42c07f1698350
BLAKE2b-256 b9e1fde4ac4a7d7d198796d6d94bd4507ca397e3e8a083eafe80c5bdac9f533f

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 92520fcf6ef7b6b544612dc7dbc0da4352d7ddc3539be6745d474403fde61f4a
MD5 115063c2abbaea7de3dc4b252ae97655
BLAKE2b-256 f1769e6d9a79a3dc8e6164c3988a6fe0e4bac5c951e6d05f5e2b96bb92974dd0

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.2.0-cp38-cp38-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.2.0-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6404cedb53c706f6e98684dc71b227646039de78d099581cc6910e681fc704a1
MD5 76af9d20f68aad2989b7f2f75d09981e
BLAKE2b-256 e23caee800ed03a6fe4bae7fc5a7d1e0e81fa57945d376361cc557f17c723773

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.2.0-cp37-none-win_amd64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.2.0-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 d9886a5936c295261a253e6497de134184365f7e66236a62c2b3f2c3096cf5b3
MD5 5fd43a37af2f27ab42d741b02ea159ce
BLAKE2b-256 66666cff6fe83a2f98c17aaf8a2ace6553c9486cebf954f3409187f379d2f322

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 71b0ec80826c3ad0c9c48af5aeb2c2086255c9d4409a3e6ec3e02165082d156a
MD5 1fb7435e21e0e054963713beebe1043c
BLAKE2b-256 21734a5be05c549996d92b57d8a6ed571fa1e03c10e8de257f003ea4a76c2278

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.2.0-cp37-cp37m-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.2.0-cp37-cp37m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7b3e8e345356d246607cd12a739fc0fbc1fc6da5ba47039ef3c83098fe50d577
MD5 288301615570a0db5d24c5dd02c5dbed
BLAKE2b-256 e92eaf2fd07d0a9f9a81fb251b792a32dfb8587fb1b97b2ba3063a70315f93f2

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