Interlude · a short detour

Two kinds of nearest

This whole site exists because of one confusing afternoon: a pixel-art workflow said nearest-neighbor, an ML refresher said nearest neighbors, and they turned out to be two completely different ideas wearing the same name. Ten minutes here untangles them permanently.

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

One copies, the other votes

Nearest-neighbor interpolation answers a graphics question: this output pixel lands between source pixels — what color should it be? Its answer is blunt: copy the single closest source pixel, no blending, no opinions. That bluntness is exactly why it’s the right tool for pixel art — flat fills stay flat and hard edges stay hard. Bilinear and bicubic answer the same question by averaging neighbors instead, which is why they turn the mushroom’s crisp outline into mush — and why they’re the right answer for photos, where smoothness is truth. Flip the source above to the gradient and the rankings invert.

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. You operated exactly that machine in the 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.

§2

Why the confusion is worth keeping

The mix-up is actually a good mnemonic, because both algorithms share a worldview: when in doubt, trust whatever is closest. Both are lazy — no training phase, all the work at lookup time. Both have one dial that trades sharpness for smoothness: interpolation picks how many source pixels to blend (one, four, sixteen — nearest, bilinear, bicubic), and KNN picks how many neighbors vote. Blend more, get smoother, lose detail. You watched that exact dial work twice now, in two different worlds.

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. (And when your image tool offers lanczos, that’s just the photo-grade end of the blending dial — a sharper windowed average for downscaling photographs.)

Bridge

Both kinds of nearest treat pixels as things to look up. The next station flips the relationship: instead of copying or polling pixels, 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 & VisionThe Convolution Bench

Paint pixels, slide kernels, watch features emerge.