Skip to main content

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.

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 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:

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.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

cykooz.resizer-2.1.2.tar.gz (20.3 kB view details)

Uploaded Source

Built Distributions

cykooz.resizer-2.1.2-cp311-none-win_amd64.whl (518.9 kB view details)

Uploaded CPython 3.11 Windows x86-64

cykooz.resizer-2.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (569.9 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

cykooz.resizer-2.1.2-cp311-cp311-macosx_10_7_x86_64.whl (560.3 kB view details)

Uploaded CPython 3.11 macOS 10.7+ x86-64

cykooz.resizer-2.1.2-cp310-none-win_amd64.whl (518.9 kB view details)

Uploaded CPython 3.10 Windows x86-64

cykooz.resizer-2.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (569.9 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

cykooz.resizer-2.1.2-cp310-cp310-macosx_10_7_x86_64.whl (560.3 kB view details)

Uploaded CPython 3.10 macOS 10.7+ x86-64

cykooz.resizer-2.1.2-cp39-none-win_amd64.whl (518.9 kB view details)

Uploaded CPython 3.9 Windows x86-64

cykooz.resizer-2.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (569.9 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

cykooz.resizer-2.1.2-cp39-cp39-macosx_10_7_x86_64.whl (560.3 kB view details)

Uploaded CPython 3.9 macOS 10.7+ x86-64

cykooz.resizer-2.1.2-cp38-none-win_amd64.whl (519.2 kB view details)

Uploaded CPython 3.8 Windows x86-64

cykooz.resizer-2.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (570.1 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

cykooz.resizer-2.1.2-cp38-cp38-macosx_10_7_x86_64.whl (560.5 kB view details)

Uploaded CPython 3.8 macOS 10.7+ x86-64

cykooz.resizer-2.1.2-cp37-none-win_amd64.whl (519.1 kB view details)

Uploaded CPython 3.7 Windows x86-64

cykooz.resizer-2.1.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (570.1 kB view details)

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

cykooz.resizer-2.1.2-cp37-cp37m-macosx_10_7_x86_64.whl (560.5 kB view details)

Uploaded CPython 3.7m macOS 10.7+ x86-64

File details

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

File metadata

  • Download URL: cykooz.resizer-2.1.2.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.5

File hashes

Hashes for cykooz.resizer-2.1.2.tar.gz
Algorithm Hash digest
SHA256 a7476a8e0d49ce895ba42d43c33edd58ed1b8c96289affe049ae4a34968ecc3c
MD5 77b3b7d6e20d50cf4fea445ad63f7f01
BLAKE2b-256 7e28bb537151c4460d7d2a780cfe2f8b045bc81f8dd1d92482c6fa61812608b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-2.1.2-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 b1b4d68e3f2ea37e05a0d83d022067bed520e9a292b3b71674cfee3ca3155404
MD5 03fa5c863521759a8871e54d7a4c37bc
BLAKE2b-256 8555871d1b17e7fb3de1f0e1a2f4ccdbf249d08c571a1a516609b47a47c27627

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-2.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 43ee69d3d46a99fe3410feb3e359f284e8f95fbe65f636efaac5fd9e9df5f91a
MD5 24282995529f4fde27ed5453aa6e07dd
BLAKE2b-256 b124c9a5a7a7c331d26d70032861783914da1957cc9efafa555617367ee2ca28

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.1.2-cp311-cp311-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.1.2-cp311-cp311-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 9c580a45362cd5f587e25cde9564f0679c243756f93a2fb5c9173271c2080524
MD5 18f7990e08f600c952fb1418dc69b98c
BLAKE2b-256 dfe1547f7415fb23a5da26f0ec77c8c0843ec8471360ef5bf2e4452ca407c7b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-2.1.2-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 71079db307dc414b770ca8f233dd07476d37dde01adef38a5af20cacb8b7c442
MD5 2d2a366a612406f4c6241050782980be
BLAKE2b-256 5832fddab93b90daca70c3789886d8f1602eafd46701b4fa4a436ae78c36efe0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-2.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 95cbac990228939b48205accbbf03a0cb524bbf0a5679ea65be5a8c2a91c7f1a
MD5 eef266b5ad77c5c66169319afd8cc474
BLAKE2b-256 6526d80586d2e0ecf106cd3f95b74ec72d5cc1371db38ee8bf85a4cb947e82c5

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.1.2-cp310-cp310-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.1.2-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 c847bfd38ade35a70f523a47123fba7c4e0bd07338bdc1c28ea75b54559ee6d1
MD5 394015714d8f8193114b70f7c3acb058
BLAKE2b-256 de4003e18850e58eece8ac294ef45c61d835825d780d38b86373c5f0edb90ce9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-2.1.2-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 a8bf0a1ffe7db5e6fe0ec50c2900c0e47452436a36290d44e50779fa51a22804
MD5 6ff8230f75c76c6304ce3be92b1e4983
BLAKE2b-256 22acb6646b7838b66ea46e12f5ff6e1249e5dec6f02a1a3376e76dd954f99b01

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-2.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 20f2dd15bc4c67f53630bd3f9cd14f40f20c86bb9f6e798e994e5ec743b4d24e
MD5 adb478f92ad991dede4cdd0bb2724e30
BLAKE2b-256 fb7a8e5802de33f6faad84bd57a5b2cf92594592d3b101bf5034b6b58d2892da

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.1.2-cp39-cp39-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.1.2-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 b343b1a9ec3e6ad3cf1c24e0be3b45b2d6d97ebf316809a42ed126ebfe1ce7ad
MD5 b7ad46b8cc67eb346496e5f4b177c99d
BLAKE2b-256 af69f7575db1822356b40c57f457efb5e044928a34cf448469cf456fc902a898

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-2.1.2-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 2e265e133defaf8b4816de6c54c7c7090ac79f8daf025a6ec119516178241698
MD5 8e5d76687482cb750ab8cd8f8f49b9f1
BLAKE2b-256 373f9a887a04a6b5f979faa0e5fee01e7823e68eab9d910a807f6ae5b8f23b35

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-2.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6aec101a895e6fbe8afa8a719282bac0d95513173d95e7b00a0dc529fff250d6
MD5 d89b73a4cee6907776f0b8f93e7ec655
BLAKE2b-256 f19f01c93ec9a29a3a4d7209aae91d52b23461d46abd4e25543715e1884ce2aa

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.1.2-cp38-cp38-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.1.2-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 cfb4d9a3fcb7e01abf0de885677d570d835341e06ec539522c485ab8deb03446
MD5 f1ad5c319251deda63ed6ef4abbda8c9
BLAKE2b-256 dfbcdc1b55fd46c94f929da02267551fec8d5304d59e5c48216faa109538912d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-2.1.2-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 aaa04dbd093339136b7e838cc56457bb9a6aa13051406cd970b7eae20ecca0f1
MD5 1418247c9d57f8f867ec2fb31a2e8fb7
BLAKE2b-256 8ab1bbd7a87d3d1b2b653b10273e0e4a98bb41883600e124e33d031f92102051

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-2.1.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 561d11d35b75f60ba5eeb0a72daad1c1bebf79a3d77cd53704023a9d1202456c
MD5 297164b1d55e6aa340e7e6ddcc8ccfb1
BLAKE2b-256 7e85dcfaea839873df2870dae0ec2753daa66fc5626dca7dce1efcea0e968027

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.1.2-cp37-cp37m-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-2.1.2-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 323976f88888a307cb8c1ad92819b75f95f3dc1a523d6bd5d2ca145035a1a479
MD5 bfe29ce6c55842ee6a9ddd0382872ce9
BLAKE2b-256 dfb6cf196e7ed5db33c78ba0aa373d3938589dac61d1e425a3d044540fd87511

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