DEV Community

Cover image for Pillow resize filters compared: size, speed and PSNR
Sahadat Husain
Sahadat Husain

Posted on

Pillow resize filters compared: size, speed and PSNR

Use Image.Resampling.LANCZOS when you shrink photos in Pillow and quality matters, and BICUBIC when time does. On a 4964 × 2782 photo shrunk to 1200 × 673, LANCZOS took 121 ms and BICUBIC 87.5 ms. NEAREST took 0.9 ms but made a larger JPEG (95,172 bytes against 88,836) with aliasing noise. On a round trip test, LANCZOS scored 32.71 dB and NEAREST 26.38 dB.

Which filters does Pillow offer?

The Pillow filter docs list NEAREST, BOX, BILINEAR, HAMMING, BICUBIC and LANCZOS for resize(). The docs say resize() defaults to BICUBIC, and that images in mode "1" or "P" always use NEAREST. They describe BOX as equal weights for every contributing pixel, and HAMMING as sharper than BILINEAR. I tested all six on photos. The newer MKS2013 and MKS2021 filters were out of scope.

The script

It runs two tests. The first shrinks the large camera photo to 1200 × 673, then times the resize, saves a JPEG at quality 80 and scores sharpness. The second shrinks a 1920 × 1280 photo to half size, scales it back up with the same filter, and compares it with the original using PSNR.

Enter fullscreen mode Exit fullscreen mode

Sharpness here is the variance of a Laplacian: a plain edge-contrast number. Higher means more contrast at edges. It cannot tell real detail from noise, which matters for NEAREST below. Times are CPU time (time.process_time()), median of 5.

What did it print?

Enter fullscreen mode Exit fullscreen mode

Bars: JPEG size at quality 80 for each filter, from 83,261 bytes for BILINEAR to 95,172 for NEAREST, with the resize time and round trip PSNR beside them

What do the numbers say?

  • NEAREST is not a quality option. It took 0.9 ms, which is 134 times faster than LANCZOS. It also wrote the biggest JPEG, 95,172 bytes, 7.1% more than LANCZOS. NEAREST copies one source pixel per output pixel, so fine texture turns into jagged noise, and noise costs bytes. Its sharpness score of 410.7 is high because of that noise, not because of detail.
  • BILINEAR gives the smallest file and the softest picture. 83,261 bytes and a sharpness of 96.9, the lowest of the six. Smaller bytes here mostly mean lost edge contrast.
  • LANCZOS keeps the most real contrast. Among the five smoothing filters it has the highest sharpness (183.6) and the best round trip score (32.71 dB). It costs 121.0 ms, against 87.5 ms for BICUBIC and 44.9 ms for BILINEAR.
  • BOX and HAMMING sit in between. BOX is cheap (23.9 ms) and scored 29.40 dB on the round trip. HAMMING took 44.9 ms and scored 29.84 dB.
  • The round trip ranks the filters LANCZOS, BICUBIC, HAMMING, BOX, BILINEAR, NEAREST. The gap from LANCZOS to BICUBIC was 1.31 dB.

Note: the round trip tests shrinking and enlarging with the same filter, so it rewards filters that also upscale well. A pure downscale ranking could differ. I used it because the original pixels are known, which gives PSNR something fair to compare against. The first test has no reference image, so it reports bytes and sharpness only.

What does the choice cost on a real page?

Take the 1200 × 673 hero image. LANCZOS wrote 88,836 bytes. BILINEAR wrote 83,261 bytes, which is 5,575 bytes (6.3% of the LANCZOS file) less. That is a real saving, and it came from a softer picture: the BILINEAR sharpness score was 96.9 against 183.6. Choosing a filter is not a free byte trade. You pick how much edge contrast to keep, and the file size follows.

On time, the gap between LANCZOS and BILINEAR was 76.1 ms per photo. Across 10,000 photos that is about 12.7 minutes of CPU. For an upload handler that serves one user, you will not notice. For a nightly job over a whole catalog, you will.

Which filter should you use?

  • Photos for the web: LANCZOS in a build step or queue worker, BICUBIC when a request waits on you.
  • Previews and quick scans: BOX, or BILINEAR if you want smoother edges at similar cost.
  • Pixel art and UI screenshots: NEAREST is the usual choice for hard edges. I did not test that case.
  • Huge shrinks: resize() takes a reducing_gap argument that shrinks by whole-number steps first. The Pillow docs describe it, and I did not test it with every filter here.

In the script the filter is one argument, so you can swap it and measure on your own photos:

small = photo.resize((1200, 673), Image.Resampling.LANCZOS)
Enter fullscreen mode Exit fullscreen mode

The resize guide explains how resizing affects quality for non-developers.

How I measured

  • Machine: Apple M1 Pro, macOS, 2026-10-18.
  • Python 3.9.6 in a fresh venv, Pillow 11.3.0, NumPy for PSNR and sharpness.
  • Inputs: image-compressor-sample-camera-photo.jpeg (4964 × 2782) and jpg-sample-photo-original.jpg (1920 × 1280) from the site.
  • Times: CPU time, median of 5. The machine was busy, so I avoided the wall clock.
  • JPEG sizes use Pillow's default settings at quality 80, with no optimize flag.

What I did not test

MKS2013 and MKS2021, upscaling beyond the round trip, alpha images, screenshots and pixel art, and a human side-by-side look at the outputs.


I build Blinkimg, an image compressor and converter with a developer API. I wrote this article with help from an AI assistant (Claude), which ran the code on my machine; every number in it comes from those runs.

Top comments (1)

Collapse
 
sss_ec8db2b6aa43a4e969595 profile image
sss •

Useful table. One Pillow knob worth adding to the timing column, because most of LANCZOS's cost on a big shrink is its kernel running over every source pixel: reducing_gap.

im.resize(size, Image.Resampling.LANCZOS, reducing_gap=2.0) first does a cheap integer box reduce() and then runs LANCZOS on the smaller image. I tried it this morning on two large Commons JPEGs shrunk to 1200 px wide (Pillow 13.0, Apple M4 Pro, process_time, median of 7, image already decoded, PSNR measured against the plain LANCZOS output):

  • 6720 × 4480: LANCZOS 104 ms; reducing_gap=2.0 45 ms at 54.1 dB; 1.5 27 ms at 50.2 dB
  • 4800 × 3200: LANCZOS 57 ms; 2.0 and 1.5 both 25 ms at 50.7 dB

reducing_gap=3.0 changed nothing on these two, because the reduce factor is the whole-number part of scale / gap, and a 4× or 5.6× shrink divided by 3 rounds down to 1.

For JPEGs there is also im.draft("RGB", size) before load(), which lets libjpeg decode at 1/2, 1/4 or 1/8 scale. It made the resize nearly free (12 ms after decoding the 6720 px file at 1680 × 1120), but it is a different filter: 45.1 dB and 39.4 dB against plain LANCZOS. On my runs the decode only got about 15–20% faster (117 → 94 ms, 96 → 81 ms), so I would use reducing_gap first and keep draft for previews.