Skip to main content

Encoding

Writing an image to a file.

Raw pixels to file bytes, at matched settings. Speed alone is not the whole story for an encoder, so each panel also shows how large the output is. Speed is the best of 7 runs; memory is the extra peak RSS of one isolated process per measurement.

encode PNG: raw pixels in, file bytes out

zlib level 6 on every side. stb bundles its own small deflate instead of zlib, so the same level does not produce the same bytes: read the speed together with the output-size table.

libstb is the reference (fastest on the most corpus entries). On average (E ⁣[tLtlibstb]\mathbb{E}\!\left[\dfrac{t_{L}}{t_{\text{libstb}}}\right], the mean of each entry's own ratio, not a ratio of medians): OpenCV 1.7×, Pillow 2.1×, imageio 2.3× as long.

libstb needs the least extra memory on the most entries (extra peak RSS on top of what the process held before the operation started; images under 0.065 MP are not measured). On average, E ⁣[mLmlibstb]\mathbb{E}\!\left[\dfrac{m_{L}}{m_{\text{libstb}}}\right]: Pillow 0.0×, OpenCV 0.0×, imageio 1.3× as much.

Output sizeE ⁣[sLsPillow]\mathbb{E}\!\left[\dfrac{s_{L}}{s_{\text{Pillow}}}\right]entries
libstb1.01×22
OpenCV1.02×22
imageio1.00×22

Throughput vs. image size (higher is better)

Time vs. image size (lower is better)

Extra peak memory vs. image size (lower is better)

encode JPEG: raw pixels in, file bytes out

Quality 90 on every side, 3-channel images only. Encoders make different size/quality trades at the same setting, so the output-size table matters as much as the time.

OpenCV is the reference (fastest on the most corpus entries). On average (E ⁣[tLtOpenCV]\mathbb{E}\!\left[\dfrac{t_{L}}{t_{\text{OpenCV}}}\right], the mean of each entry's own ratio, not a ratio of medians): Pillow 1.2×, imageio 2.1×, libstb 2.2× as long.

OpenCV needs the least extra memory on the most entries (extra peak RSS on top of what the process held before the operation started; images under 0.065 MP are not measured).

Output sizeE ⁣[sLsPillow]\mathbb{E}\!\left[\dfrac{s_{L}}{s_{\text{Pillow}}}\right]entries
libstb0.99×18
OpenCV1.00×18
imageio1.00×18

Throughput vs. image size (higher is better)

Time vs. image size (lower is better)

Extra peak memory vs. image size (lower is better)

encode BMP: raw pixels in, file bytes out

Uncompressed, so this is mostly memory bandwidth. 3-channel images only.

OpenCV is the reference (fastest on the most corpus entries). On average (E ⁣[tLtOpenCV]\mathbb{E}\!\left[\dfrac{t_{L}}{t_{\text{OpenCV}}}\right], the mean of each entry's own ratio, not a ratio of medians): Pillow 2.0×, libstb 2.3×, imageio 5.1× as long.

OpenCV needs the least extra memory on the most entries (extra peak RSS on top of what the process held before the operation started; images under 0.065 MP are not measured). On average, E ⁣[mLmOpenCV]\mathbb{E}\!\left[\dfrac{m_{L}}{m_{\text{OpenCV}}}\right]: Pillow 1.1×, libstb 13.7×, imageio 18.2× as much.

Output sizeE ⁣[sLsPillow]\mathbb{E}\!\left[\dfrac{s_{L}}{s_{\text{Pillow}}}\right]entries
libstb1.00×18
OpenCV1.00×18
imageio1.00×18

Throughput vs. image size (higher is better)

Time vs. image size (lower is better)

Extra peak memory vs. image size (lower is better)

encode TGA: raw pixels in, file bytes out

Uncompressed on every side (libstb with rle=False, matching Pillow's default). OpenCV has no TGA encoder.

Pillow is the reference (fastest on the most corpus entries). On average (E ⁣[tLtPillow]\mathbb{E}\!\left[\dfrac{t_{L}}{t_{\text{Pillow}}}\right], the mean of each entry's own ratio, not a ratio of medians): libstb 1.4×, imageio 2.3× as long.

Pillow needs the least extra memory on the most entries (extra peak RSS on top of what the process held before the operation started; images under 0.065 MP are not measured). On average, E ⁣[mLmPillow]\mathbb{E}\!\left[\dfrac{m_{L}}{m_{\text{Pillow}}}\right]: libstb 4.9×, imageio 5.8× as much.

Output sizeE ⁣[sLsPillow]\mathbb{E}\!\left[\dfrac{s_{L}}{s_{\text{Pillow}}}\right]entries
libstb1.00×22
imageio1.00×22

Throughput vs. image size (higher is better)

Time vs. image size (lower is better)

Extra peak memory vs. image size (lower is better)