The myth of infinite detail: Bilinear vs. Bicubic

Have you ever noticed how, in movies and television, actors can take a crappy, grainy low-res traffic camera picture of a distant automobile and somehow "enhance" the image until they can read the license plate perfectly?

Yeah.

I don't know what kind of crazy infinite-detail fractal images these scriptwriters think we have. Here in the real world, bitmaps don't scale worth a damn. Take this bitmap, for example:

Hello Kitty, biatch!

If we blow that up 300% using the simplest possible algorithm ‐ a naive nearest neighbor (aka pixel resize) approach – we get this:

Hello Kitty, enlarged 300% using naive nearest neighbor

Pixel-tastic! But there's a well known way of interpolating the pixels in the image so it doesn't look quite so bad when upsized – something called bilinear filtering. Bilinear filtering samples nearby pixels in an effort to guesstimate what the missing pixels would look like in a larger image. Let's enlarge the image 300% using bilinear filtering and see what happens:

Hello Kitty, enlarged 300% using Bilinear Filtering

A bit blurry, yes, but clearly superior to giant chunky pixels.

There's also something called bicubic filtering which is supposed to be an improvement over bilinear filtering. Video cards have offered bilinear filtering for years, but they don't bother with bicubic filtering to this day. And that's with millions of transistors to burn. If bicubic is only offered by paint programs, you have to wonder, is it really worth it? Here's the same image enlarged 300% using bicubic filtering:

Hello Kitty, enlarged 300% using Bicubic Filtering

Interesting. It's sharper, but I'm not sure it's all that much better. And there's a bit of an oversharpening or halation effect at some color borders, too.

There's another image sample at Interpolate This with a writeup that implies that bicubic is flat-out superior, but I'm not sure that's the case. Either way you're interpolating*, it's just a question of how sharp you like your simulated pixels to be.

The best solution of all is to move to a vector representation and give up on bitmaps – and interpolation – entirely.

* A reader pointed out an interesting algorithm for interpolating low-res images called 2xSAI. Here's a screenshot I generated of a SNES game with 2xSAI interpolation enabled. Compare to the original screenshot.

Read more

Stay Gold, America

We are at an unprecedented point in American history, and I'm concerned we may lose sight of the American Dream.

By Jeff Atwood · · Comments

The Great Filter Comes For Us All

With a 13 billion year head start on evolution, why haven't any other forms of life in the universe contacted us by now? (Arrival is a fantastic movie. Watch it, but don't stop there - read the Story of Your Life novella it was based on

By Jeff Atwood · · Comments

I Fight For The Users

If you haven't been able to keep up with my blistering pace of one blog post per year, I don't blame you. There's a lot going on right now. It's a busy time. But let's pause and take a moment

By Jeff Atwood · · Comments

The 2030 Self-Driving Car Bet

It's my honor to announce that John Carmack and I have initiated a friendly bet of $10,000* to the 501(c)(3) charity of the winner’s choice: By January 1st, 2030, completely autonomous self-driving cars meeting SAE J3016 level 5 will be commercially available for passenger

By Jeff Atwood · · Comments