Skip to main content

Join the wonderland of python, and decode all your images in a numpy compatible way

Project description

redpil

pypi Travis Docs

Join the wonderland of python, and decode all your images in a numpy compatible way.

Pillow is a great library for image manipulation. However, many operations fall outside what Pillow can do. As such, many scientific applications require the image to be available as a numpy array. However, Pillow's memory system is largely incompatible with numpy's. imageio has created an efficient bridge between numpy and Pillow (see benchmarks below). Unfortunately, Pillow's multitude of options remain confusing it is challenging to understand how they all operate together. Furthermore, the code base is rather old, written in C, meaning that it is difficult to extend the functionality of existing decoders.

For large images, having to understand the details of both Pillow and numpy is a serious bottleneck. The goal of the library it to read and write images in a manner natural to numpy users. Images are presented as the values they hold (not indices in a color table) allowing for direct data analysis.

As much as possible, the library is written in python allowing for new decoding algorithms to be played around with.

Bitmap images

Generally, this library will not load memory in a C-contiguous array. Rather the memory order will mostly match what was saved on disk.

Bitmap images will be stored in an order similar to how they arranged in RAM.

Supported file formats

Reading BMP is almost fully supported. Writing is still limited.

Future file formats

  • BMP: more coverage
  • JPEG, JPEG2000
  • GIF
  • PNG
  • SVG
  • TIFF

Benchmarks

I don't have a fancy benchmarking service like scikit-image or dask has, but here are the benchmarks results compared to a PIL backend. This is running on my SSD, a Samsung 960 Pro which claims it can write at 1.8GB/s. This is pretty close to what redpil achieves.

8 bit BMP grayscale images

Saving images:

================ ============ ============ ============
--                                mode                 
---------------- --------------------------------------
     shape          redpil       pillow      imageio   
================ ============ ============ ============
   (128, 128)      93.4±1μs     254±30μs     369±20μs  
  (1024, 1024)     720±30μs     936±50μs    1.60±0.3ms
  (2048, 4096)    5.25±0.7ms   5.20±0.1ms    10.4±2ms  
 (32768, 32768)    480±10ms     489±5ms     1.34±0.09s
================ ============ ============ ============

Reading image

================ ============= ============ =============
--                                 mode                  
---------------- ----------------------------------------
     shape           redpil       pillow       imageio   
================ ============= ============ =============
   (128, 128)       131±5μs      293±10μs      130±2μs   
  (1024, 1024)      194±10μs    1.03±0.1ms     192±5μs   
  (2048, 4096)    1.69±0.05ms    8.55±1ms    1.67±0.03ms
 (32768, 32768)     350±3ms      230±5μs       354±10ms  
================ ============= ============ =============

Note, Pillow refuses to read the 1GB image because it thinks it is a fork bomb.

Patched up imageio

As it can be seen, the team at imageio/scikit-image are much better at reading the pillow documentation and understanding how to use it effectively. Their reading speeds actually match the reading speeds of redpil, even though they use pillow as a backend. They even handle what pillow thinks is a forkbomb.

Through writing this module, two bugs were found in imageio that affect the speed of saving images imageio PR #398, and how images were being read imageio PR #399

With PR 398, the saving speed of imageio+pillow now matches that of redpil. Note I'm always using the computer when running benchmarks, so take the exact numbers with a grain of salt.

Saving

================ ============ ============ ============
--                                mode                 
---------------- --------------------------------------
     shape          redpil       pillow      imageio   
================ ============ ============ ============
   (128, 128)      98.3±4μs     245±7μs      350±4μs   
  (1024, 1024)     714±20μs     921±30μs     997±20μs  
  (2048, 4096)    4.83±0.3ms   5.30±0.4ms   5.26±0.2ms
 (32768, 32768)    520±40ms     516±30ms     489±9ms   
================ ============ ============ ============

Reading

================ ============= ============ =============
--                                 mode                  
---------------- ----------------------------------------
     shape           redpil       pillow       imageio   
================ ============= ============ =============
   (128, 128)      129±0.7μs     284±2μs      129±0.7μs  
  (1024, 1024)      191±2μs     1.12±0.1ms    190±0.9μs  
  (2048, 4096)    1.62±0.03ms    8.88±1ms    1.63±0.02ms
 (32768, 32768)     357±9ms      223±4μs       361±8ms   
================ ============= ============ =============

History

0.0.1 (2018-09-22)

  • First release on PyPI.

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

redpil-0.0.5.tar.gz (32.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

redpil-0.0.5-py2.py3-none-any.whl (11.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file redpil-0.0.5.tar.gz.

File metadata

  • Download URL: redpil-0.0.5.tar.gz
  • Upload date:
  • Size: 32.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.7

File hashes

Hashes for redpil-0.0.5.tar.gz
Algorithm Hash digest
SHA256 a6a47db772864ab17cd5590c29cf79e622e9846aae95660469b8bdde93909001
MD5 9c889601333162f0e58a9db98f9f70f0
BLAKE2b-256 92b4817aed138ca08e0edb426d797c6743aeab72a4d8b3c981d0d76463b3c126

See more details on using hashes here.

File details

Details for the file redpil-0.0.5-py2.py3-none-any.whl.

File metadata

  • Download URL: redpil-0.0.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.7

File hashes

Hashes for redpil-0.0.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e49df7bd6991c56bcd66ea472da62bfe8d8e84e06d1f9f077641fb133b0297ed
MD5 017c22ba550bd70d129b82d3b66e8d8b
BLAKE2b-256 6913671b4877088a0c24487f78fd1fb28461e902804e80ade9cf8f46a52071aa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page