Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fair competition #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Fair competition #4

wants to merge 3 commits into from

Conversation

homm
Copy link

@homm homm commented Oct 14, 2018

This makes the comparison a bit more fair.

  1. Pillow loads image codecs lazily. This heavily affects max time of header tests and slightly affects avg time. Image.init() call at start of the script fixes this.

Before:

JPEG 1920x1080 header read:	1920x1080,	avg: 0.053078 ms	min: 0.038862 ms	max: 95.713854 ms
PNG 1920x1080 header read:	1920x1080,	avg: 0.050190 ms	min: 0.043869 ms	max: 0.578165 ms
WEBP 1920x1080 header read:	1920x1080,	avg: 3.311477 ms	min: 0.232935 ms	max: 248.356104 ms
GIF 1920x1080 header read:	1920x1080,	avg: 0.033193 ms	min: 0.028849 ms	max: 5.729914 ms

After:

JPEG 1920x1080 header read:	1920x1080,	avg: 0.078423 ms	min: 0.073910 ms	max: 0.518084 ms
PNG 1920x1080 header read:	1920x1080,	avg: 0.053475 ms	min: 0.049829 ms	max: 0.409842 ms
WEBP 1920x1080 header read:	1920x1080,	avg: 0.961201 ms	min: 0.244856 ms	max: 8.344889 ms
GIF 1920x1080 header read:	1920x1080,	avg: 0.044504 ms	min: 0.036955 ms	max: 9.562016 ms
  1. Lilliput uses INTER_AREA interpolation for OpenCV's resize function. Pillow uses a very flexible and high-quality resize based on convolutions. It allows to choose exact quality pf resizing and also affects performance. LANCZOS produces very harp images which looks much better than INTER_AREA interpolation. This affects not only the resize speed itself, but also speed of compression and the result size of coded images. BICUBIC filter a bit cheaper and its result is much closer to INTER_AREA, while still slightly better and shaper.

Before:

JPEG 1920x1080 => 800x600:	112307 Bytes,	avg: 32.13 ms	min: 30.00 ms	max: 41.77 ms
PNG 1920x1080 => 800x600:	846202 Bytes,	avg: 267.92 ms	min: 263.95 ms	max: 328.71 ms
WEBP 1920x1080 => 800x600:	92466 Bytes,	avg: 134.70 ms	min: 131.66 ms	max: 180.58 ms
GIF 1920x1080 => 800x600:	411470 Bytes,	avg: 102.21 ms	min: 98.08 ms	max: 129.57 ms

After:

JPEG 1920x1080 => 800x600:	107480 Bytes,	avg: 29.71 ms	min: 28.45 ms	max: 37.43 ms
PNG 1920x1080 => 800x600:	810489 Bytes,	avg: 278.79 ms	min: 270.78 ms	max: 336.85 ms
WEBP 1920x1080 => 800x600:	84690 Bytes,	avg: 132.98 ms	min: 128.04 ms	max: 304.28 ms
GIF 1920x1080 => 800x600:	411470 Bytes,	avg: 100.53 ms	min: 96.06 ms	max: 145.06 ms
  1. There is an absolutely unnecessary conversion of color mode for Pillow. It adds some overheads and also converts PNG and WEBP images to RGBA mode. As a result, the size is bigger and compression is slower.

@WardBenjamin
Copy link

I highly support this being merged, along with the other open PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants