by planede · 3y ago · 0 comments
1. The form of interpolation (this article).
2. The colorspace used for doing the arithmetic for interpolation. You most likely want a linear colorspace here.
3. Clipping. Resizing is typically done in two phases, once resizing in x then in y direction, not necessarily in this order. If the kernel used has values outside of the range [0, 1] (like Lanczos) and for intermediate results you only capture the range [0,1], then you might get clipping in the intermediate image, which can cause artifacts.
4. Quantization and dithering.
5. If you have an alpha channel, using pre-multiplied alpha for interpolation arithmetic.
I'm not trying to be exhaustive here. ImageWorsener's page has a nice reading list[1].
One pet peeve of mine is algorithms for making thumbnails, most of the algorithms from the image processing book don't really apply as they are usually trying to interpolate between points based on a small neighborhood whereas if you are downscaling by a large factor (say 10) the obvious thing to do is sample the pixels in the input image that intersect with the pixel in the output image (100 in that case.)
That box averaging is a pretty expensive convolution so most libraries usually downscale images by powers of 2 and then interpolate from the closest such image which I think is not quite perfect and I think you could do better.
Practically people think that box averaging is too expensive (pretty much it is like that Gaussian blur but computed on fewer output points.)
>> The definition of scaling function is mathematical and should never be a function of the library being used.
I could just as easily say "hey, why is you NN affected by image artifacts, isn't it supposed to be robust?"
Also, gamut clipping and interpolation[0]. That's a real rabbithole.
[0] https://www.cis.rit.edu/people/faculty/montag/PDFs/057.PDF (Downloads a PDF)
Here is the most popular article about this problem [1].
Warning: once you start noticing incorrect color blending done in sRGB space, then you will see it everywhere.
It is unquestionably superior though.
Upscaling is much more difficult.
Here is imageworsener's article about this[1]
Of course if you're not interpolating but downscaling the image (which isn't really an interpolation, the value at a particular position in the image does not remain the same) then you do want a linear colourspace to avoid brightening / darkening details, but you need a perceptual colourspace to minimize ringing etc. It's an interesting puzzle.