Skip to content

Interlude · a short detour

Nearest-neighbor interpolation vs. bilinear and bicubic

Enlarging a picture creates new pixels. Nearest neighbor copies the closest source pixel; bilinear blends four nearby pixels; bicubic uses a curve across a 4×4 neighborhood. Compare them below to see why crisp pixel art and smooth images need different treatment.

Try the resizing comparison ↓

One image, three ways to enlarge it

Start with pixel art and look at the mushroom’s outline. Then select smooth gradient below the images and compare the color transitions. Which method keeps the blocks, and which fills in the steps between them?

Resampling bench — one source, three interpolators
16×16 → 176×176
source · 16×16
nearest
bilinear
bicubic

flat fills + hard edges: nearest wins, the interpolators turn ink into mush

fig. 01 — the same 16×16 source through three resamplers, computed by hand

§1

Which interpolation method should you use?

For enlarging pixel art, start with nearest neighbor. For photos and gradients, compare bilinear and bicubic: bilinear gives a softer result, while bicubic can keep edges more defined. The most useful choice depends on the image and the look you want.

Nearest neighbor vs. bilinear vs. bicubic when enlarging an image
MethodHow it samplesUseful forWatch for
Nearest neighborCopies one source pixel.Pixel art and images whose exact palette should stay intact.Blocky steps on curves and gradients.
BilinearBlends a 2×2 neighborhood using distance weights.Smooth transitions with a simple, soft result.Blurred edges and new colors in pixel art.
BicubicUses cubic interpolation across a 4×4 neighborhood.Photos and smooth images where edge definition matters.Possible halos near sharp edges; results vary by cubic filter.

These neighborhoods describe enlargement in this demo. When shrinking an image, antialiasing and the area covered by each output pixel also matter; resizing tools can use wider filters. For a reference implementation, see Pillow’s resampling filter documentation.

§2

Why does pixel art get blurry when resized?

Bilinear and bicubic create intermediate colors around an edge. That helps a photo look continuous, but it softens the deliberate blocks in a sprite. Nearest neighbor preserves the original colors. Use a whole-number scale, such as 2× or 4×, to keep every source pixel the same size: a 16×16 sprite becomes 32×32 or 64×64.

At a non-integer scale, nearest neighbor still copies the original colors, but some blocks can become wider than others. And none of these methods recovers detail that the original image never contained: smoother enlargement is still an estimate from the available pixels.

§3

Is nearest-neighbor interpolation the same as KNN?

No. Nearest-neighbor interpolation copies a color from the closest pixel in an image grid. K-nearest neighbors (KNN) makes a prediction from nearby training examples in feature space. The shared idea is distance; what counts as a neighbor, and what you do with it, differs.

K-nearest-neighbors answers a prediction question: here is a new sample — what label should it get? Its answer is social: find the k closest training examples in feature space and let them vote. Try that prediction process in the interactive KNN decision-boundary lab. Same word, same “closest thing wins” instinct — but one copies a color from a grid, and the other polls labeled data to make a decision.

§4

Two kinds of nearest: how this lab began

This whole site exists because of one confusing afternoon: a pixel-art workflow said “nearest-neighbor,” an ML refresher said “nearest neighbors,” and I initially treated them as the same idea. Building these experiments helped me separate image resizing from learning with examples.

One more habit worth keeping: the word nearest should always trigger the question “nearest what?” Nearest pixel in a grid → graphics. Nearest sample in feature space → machine learning.

Bridge

Resizing changes where pixels go. The next station asks what those pixels contain: a convolutional network runs little learned pattern-detectors across them — and suddenly pixels aren’t data to fetch, they’re evidence to interpret.

Next station · 03

CNNs & Vision — The Convolution Bench

Paint pixels, slide kernels, watch features emerge.