◩ Graphics & images

Interpolation and resampling: bilinear, bicubic and Lanczos

What happens when you resize an image: nearest neighbour, bilinear, bicubic, Lanczos, aliasing and moiré, and which filter to choose in each case.

Resizing an image means building a new pixel grid from the existing one. The new sampling points almost never coincide with the old ones, so the program has to estimate the missing values. The method it uses is called interpolation or the resampling filter, and the choice affects sharpness, halos, jaggies and unwanted patterns. It is worth understanding the differences rather than always leaving the default setting.

Enlarging and reducing are different problems

  • When enlarging, values must be created between the existing samples. No classical method adds real detail: you only choose how to fill the gaps, softer or sharper.
  • When reducing, many original pixels merge into one. The main risk is not blur but aliasing: detail finer than the new grid can turn into false patterns.

That is why a filter that is excellent for enlarging is not necessarily the best for reducing.

The main methods

Nearest neighbour

Each new pixel takes the value of the nearest original pixel. No averaging, no new colors.

  • Pros: very fast, preserves the original colors exactly, keeps edges hard.
  • Cons: blocky enlargements, reductions full of aliasing.
  • When to use it: pixel art, icons enlarged by integer factors, index maps or masks where intermediate values must not appear.

Bilinear

The new value is a weighted average of the four nearest pixels, based on distance.

  • Pros: fast and free of obvious jaggies.
  • Cons: softens; in strong reductions it considers only four pixels and skips intermediate detail, producing aliasing.

Bicubic

It considers the sixteen nearest pixels and uses third-degree curves. There are several variants with different parameters: some softer, others crisper.

  • Pros: a good balance between sharpness and smoothness; it is the default in many programs.
  • Cons: the sharper variants produce slight halos around high-contrast edges.

Lanczos

It uses a function derived from the cardinal sine (sinc), truncated over a window of two or three pixels on each side. It comes close to theoretically ideal resampling.

  • Pros: very sharp results, especially when reducing.
  • Cons: slower and prone to ringing, light and dark halos around very sharp edges, such as black text on white.
Method Pixels considered Sharpness Main risk
Nearest neighbour 1 maximum, blocky jaggies, aliasing
Bilinear 4 low blur, aliasing when reducing
Bicubic 16 medium-high slight halos
Lanczos (3) 36 high ringing

Aliasing and moiré when reducing

The sampling theorem says, in essence, that a grid cannot represent detail finer than half its own frequency. If you shrink a photo of a finely striped shirt without first removing that detail, the stripes turn into wavy bands that do not exist: this is moiré.

Good reduction algorithms do two things:

  1. they apply a low-pass filter proportional to the reduction factor, that is, they consider all the pixels that merge into the new one;
  2. only then do they sample the new grid.

Many libraries do this automatically when you use bicubic or Lanczos filters, but not always with bilinear. A practical trick, if the tool does not, is to reduce in several successive steps of 50% each, which approximates correct filtering.

Advice for real cases

  • Photos for the web: reduce with bicubic or Lanczos, then apply a light unsharp mask at the final size. Sharpening should be adjusted after reduction, not before.
  • Screenshots and interfaces: avoid non-integer factors where possible. Reducing to exactly 50% gives much cleaner results than 47%.
  • Pixel art and sprites: nearest neighbour with integer factors (2×, 3×, 4×).
  • Masks, segmentation maps, indexed images: nearest neighbour, otherwise meaningless values appear.
  • Images with transparency: premultiply alpha before resizing to avoid dark edges.
  • Remember gamma: for accurate results, especially with light detail on a dark background, resampling should be done in linear light.

What about "intelligent" upscaling?

There are now neural-network upscaling methods that produce more detailed images than classical filters. It is important to understand what they do: they do not recover information present in the original, they generate plausible detail based on what they have learned from other images. For creative use they can be helpful; in my analysis work, where what matters is what the image really contains, an upscale of this kind cannot be treated as evidence of a detail.

In short

  • Resizing means estimating values on a new grid; enlarging and reducing pose different problems.
  • Nearest neighbour for pixel art and masks; bicubic or Lanczos for photographs.
  • When reducing, the enemy is aliasing: the filter must take into account all the pixels that merge.
  • Sharpening is adjusted after resizing, at the final size.
  • Neural-network upscalers invent plausible detail; they do not recover it.
MM
Marco Marzaduri

Marco Marzaduri works in cybersecurity, digital forensics and web development. A computer science graduate, he combines rigorous technical analysis with attention to the people who use technology.

Read also