- Notifications
You must be signed in to change notification settings - Fork102
uploadcare/pillow-simd
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Pillow-SIMD is highly optimized version ofPillow libraryfor x86 architecture (mainly Intel and AMD CPUs).
Pillow-SIMD is "following" Pillow which means it isdrop-in replacements for Pillow of the same version.For example,Pillow-SIMD 3.2.0.post3 is a drop-in replacement forPillow 3.2.0, andPillow-SIMD 3.3.3.post0 — forPillow 3.3.3.
For more information on the original Pillow, please refer to:read the documentation,check the changelog andfind out how to contribute.
There are multiple ways to tweak image processing performance.To name a few, such ways can be: utilizing better algorithms, optimizing existing implementations,using more processing power and/or resources.One of the great examples of using a more efficient algorithm isreplacinga convolution-based Gaussian blur with a sequential-box one.
Such examples are rather rare, though. It is also known, that certain processes might be optimizedby using parallel processing to run the respective routines.But a more practical key to optimizations might be making things work fasterusing the resources at hand. For instance, SIMD computing might be the case.
SIMD stands for "single instruction, multiple data" and its essence isin performing the same operation on multiple data points simultaneouslyby using multiple processing elements.Common CPU SIMD instruction sets are MMX, SSE-SSE4, AVX, AVX2, AVX512, NEON.
Currently, Pillow-SIMD can becompiled with SSE4 (default) or AVX2 support.
Pillow-SIMD project is production-ready.The project is supported by Uploadcare, a SAAS for cloud-based image storing and processing.
In fact, Uploadcare has been running Pillow-SIMD since 2015.
The following image operations are currently SIMD-accelerated:
- Resize (convolution-based resampling): SSE4, AVX2
- Gaussian and box blur: SSE4
- Alpha composition: SSE4, AVX2
- RGBA → RGBa (alpha premultiplication): SSE4, AVX2
- RGBa → RGBA (division by alpha): SSE4, AVX2
- RGB → L (grayscale): SSE4
- 3x3 and 5x5 kernel filters: SSE4, AVX2
- Split and get_channel: SSE4
Tons of tests can be found on thePillow Performance page.There are benchmarks against different versions of Pillow and Pillow-SIMDas well as ImageMagick, Skia, OpenCV and IPP.
The results show that for resizing Pillow is always faster than ImageMagick,Pillow-SIMD, in turn, is even faster than the original Pillow by the factor of 4-6.In general, Pillow-SIMD with AVX2 is always16 to 40 times faster thanImageMagick and outperforms Skia, the high-speed graphics library used in Chromium.
No cheats involved. We've used identical high-quality resize and blur methods for the benchmark.Outcomes produced by different libraries are in almost pixel-perfect agreement.The difference in measured rates is only provided with the performance of every involved algorithm.
Because of the SIMD computing, of course. But there's more to it:heavy loops unrolling, specific instructions, which aren't available for scalar data types.
Well, it's not that simple. First of all, the original Pillow supportsa large number of architectures, not just x86.But even for x86 platforms, Pillow is often distributed via precompiled binaries.In order for us to integrate SIMD into the precompiled binarieswe'd need to execute runtime CPU capabilities checks.To compile the code this way we need to pass the-mavx2 option to the compiler.But with the option included, a compiler will inject AVX instructions evenfor SSE functions (i.e. interchange them) since every SSE instruction has its AVX equivalent.So there is no easy way to compile such library, especially with setuptools.
If there's a copy of the original Pillow installed, it has to be removed firstwith$ pip uninstall -y pillow.Please installprerequisites for your platform.The installation itself is simple just as running$ pip install pillow-simd,and if you're using SSE4-capable CPU everything should run smoothly.If you'd like to install the AVX2-enabled version,you need to pass the additional flag to a C compiler.The easiest way to do so is to define theCC variable during the compilation.
$ pip uninstall pillow$ CC="cc -mavx2" pip install -U --force-reinstall pillow-simdPlease be aware that Pillow-SIMD and Pillow are two separate projects.Please submit bugs and improvements not related to SIMD to theoriginal Pillow.All bugfixes to the original Pillow will then be transferred to the next Pillow-SIMD version automatically.
About
The friendly PIL fork
Resources
License
Code of conduct
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Languages
- Python60.0%
- C38.7%
- HTML0.5%
- PostScript0.4%
- Shell0.2%
- Makefile0.1%
- Other0.1%