Skip to content

Comment on The dangers behind image resizing (2021)

Comments

The definition of scaling function is mathematical and should never be a function of the library being used.

Horseshit. Image resizing or any other kind of resampling is essentially always about filling in missing information. The is no mathematical model that will tell you for certain what the missing information is.

Not at all. He is correct that those functions are defined mathematically and that the results should therefore be the same using any libraries which claim to implement them.

An example used in the article: https://en.wikipedia.org/wiki/Lanczos_resampling

Arguably downscaling does not fill in missing information, it only throws away information. Still, implementations vary a lot here. There might not be a consensus of a unique correct way to do downscaling, but there are certain things that you certainly don't want to do. Like doing naive linear arithmetic on sRGB color values.

Interpolation is still filling in missing information, it's just possible to get a pretty good estimate.

This is wrong. Interpolation below Nyquist (downsampling) results in a subset of the original Information (capital I information theory information).

Images aren't bandlimited so the conditions don't apply for that.

That's why a vector image rendered at 128x128 can look better/sharper than one rendered at 256x256 and scaled down.

They are band-limited. That's why you get aliasing when taking unfiltered photos above Nyquist without AA filters.

In your example the lower res image would be using most of its bandwidth while the higher res image would be using almost none of its bandwidth.

Images are 2D discrete signals. Everything you know about 1D DSP applies to them.

If some of the edges are infinitely sharp, and you know which ones they are by looking at them, as in my example, then it's using more than all its bandwidth at any resolution.

That's true in the 1D case as well. That requires upsampling with information generation before downsampling. Using priori to guess missing information is a task that will never be finished and is interesting. It isn't necessary for a satisfactory downsampling result.

One interesting complication for a lot of photos is that the bandwidth of the green channel is twice as high as the red and blue channels due to the Bayer filter mosaic.

Aha, no! Downscaling *into a discrete space by an arbitrary amount* is absolutely filling in missing information.

Take the naive case where you downscale a line of four pixels to two pixels - you can simply discard two of them so you go from `0,1,2,3` to `0,2`. It looks okay.

But what happens if you want to scale four pixels to three? You could simply throw one away but then things will look wobbly and lumpy. So you need to take your four pixels, and fill in a missing value that lands slap bang between 1 and 2. Worse, you actually need to treat 0 and 3 as missing values too because they will be somewhat affected by spreading them into the middle pixel.

So yes, downscaling does have to compute missing values even in your naive linear interpolation!

Take the naive case where you downscale a line of four pixels to two pixels - you can simply discard two of them so you go from `0,1,2,3` to `0,2`. It looks okay.

This is already wrong, unless the pixels are band-limited to Nyquist/4. Trivial example where this is not true:

  1 0 1 0
If such a signal is decimated by 2 you get
  1 1
Which is not correct.

For downscaling, area averaging is simple and makes a lot of intuitive sense and gives good results. To me it's basically the definition of downscaling.

Like yeah, you can try to get clever and preserve the artistic intent or something with something like seamcarving but then I wouldn't call it downscaling anymore.

Hmm, maybe I was wrong then!

The article talks about downsampling, not upsampling, just so we are clear about that.

And besides, a ranty blog post pointing out pitfall can still be useful for someone else coming from the same naïve (in a good/neutral way) place as the author.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.