Editing
Operations on pixels that keep the image size.
Crop, quarter turn, flip, RGB to gray and alpha compositing: the operations libstb added for working on pixels without leaving the library, against Pillow and OpenCV where they have one. Speed is the best of 7 runs; memory is the extra peak RSS of one isolated process per measurement.
crop: the central half of each side
A new, independent image in every library (an OpenCV slice is a view, so it is copied). This is mostly memory bandwidth. 3-channel images only.
libstb is the reference (fastest on the most corpus entries). On average (, the mean of each entry's own ratio, not a ratio of medians): OpenCV 1.2×, Pillow 2.1× 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).
Throughput vs. image size (higher is better)
Time vs. image size (lower is better)
Extra peak memory vs. image size (lower is better)
rotate: a counter-clockwise quarter turn
Pillow's transpose(ROTATE_90) and cv2.rotate against libstb's rotate90. A turn reads rows and writes columns, so it is about memory access patterns. 3-channel images only.
OpenCV is the reference (fastest on the most corpus entries). On average (, the mean of each entry's own ratio, not a ratio of medians): libstb 1.2×, Pillow 1.6× 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).
Throughput vs. image size (higher is better)
Time vs. image size (lower is better)
Extra peak memory vs. image size (lower is better)
flip left to right
Pillow's transpose(FLIP_LEFT_RIGHT) and cv2.flip against libstb's flip_horizontal. 3-channel images only.
OpenCV is the reference (fastest on the most corpus entries). On average (, the mean of each entry's own ratio, not a ratio of medians): libstb 1.4×, Pillow 1.6× 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).
Throughput vs. image size (higher is better)
Time vs. image size (lower is better)
Extra peak memory vs. image size (lower is better)
convert: RGB to gray
libstb and Pillow use the same integer formula and give identical pixels; OpenCV's BGR2GRAY rounds slightly differently. libstb runs the fastest SIMD backend of the CPU it is measured on (libstb.simd_name()). 3-channel images only.
OpenCV is the reference (fastest on the most corpus entries). On average (, the mean of each entry's own ratio, not a ratio of medians): libstb 1.2×, Pillow 1.7× 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).
Throughput vs. image size (higher is better)
Time vs. image size (lower is better)
Extra peak memory vs. image size (lower is better)
composite: RGBA over RGBA, straight alpha
An RGBA image laid over its own upside-down copy, against Pillow's Image.alpha_composite (OpenCV has no equivalent). The alpha channel is identical; the colour is within one level where the pixel is visible. 4-channel images only, so only the graphics images take part.
libstb is the reference (fastest on the most corpus entries). On average (, the mean of each entry's own ratio, not a ratio of medians): Pillow 2.6× 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, : Pillow 1.0× as much.