from Hacker News

A smooth and sharp image interpolation you probably haven't heard of

by okaleniuk on 4/29/24, 6:08 PM with 50 comments

  • by GrantMoyer on 5/2/24, 12:00 PM

    With k = 1/x, the inverse weight interpolation is equivalent to bilinear. Perhaps it's better to show the result for k = 1/x^2.

    Neat aside, k = 1/x^∞ seems to be equivalent to nearest neighbor. (please excuse the abuse of notation)

  • by ImHereToVote on 5/2/24, 10:18 AM

    Why aren't the results of different interpolation methods shown in the website?
  • by jasonjmcghee on 5/2/24, 4:19 PM

    I found the original "pixelated" image to look higher resolution / crisper / more detailed.

    Really at any size I tried, I found the "upscale" to look blurry / low quality.

    Am I an outlier here?

  • by Asooka on 5/2/24, 10:42 AM

    I am a bit confused how the formula is different from a simple lerp.

        k(x) = 1/x
        
            y_i * k(x - x_i) + y_i+1 * k(x_i+1 - x)
        F = --------------------------------------- =
                 k(x - x_i) + k(x_i+1 - x)
        
          y_i / (x - x_i) + y_i+1 / (x_i+1 - x)
        = --------------------------------------- =
               1 / (x - x_i) + 1 / (x_i+1 - x)
        
          y_i * (x_i+1 - x) / A + y_i+1 * (x - x_i) / A
        = ---------------------------------------------
               (x_i+1 - x) / A + (x - x_i) / A
        
        where A = (x - x_i) * (x_i+1 - x)
        scaling to x_i+1 - x_i = 1, and using a = (x - x_i)
        
        F = (1 - a) * y_i + a * y_i+1
    
    The only time this wouldn't hold is when A = 0, but then F is not defined anyway. However, the graph of F shown is decidedly not that of the lerp function.
  • by Dwedit on 5/2/24, 3:48 PM

    My go-to for any kind of very fast image upscaling is the SuperXBR algorithm. It's fast, a pixel shader implementation runs at over 60FPS on Skylake IGP.

    SuperXBR is in the family of Edge-Directed interpolation algorithms, so diagonal or curved lines will properly maintain their shape when upscaled, and not produce "staircase" artifacts that you see with other classical interpolation. It does not improve the sharpness though, images will still look blurry after being upscaled, just like when you perform bilinear upscaling.

    But if you are doing any kind of non-realtime image upscaling today, you'd want to use the modern AI algorithms, such as Waifu2x or ESRGAN.

  • by roger_ on 5/2/24, 10:38 AM

  • by Dylan16807 on 5/2/24, 4:21 PM

    When I think of "smooth and sharp" my mind goes to, uh, I guess "sharp bilinear" is the most common term?

    It's like nearest neighbor interpolation but with less artifacting when the zoom is not an integer. The middle of each source pixel becomes a solid color block, and then bilinear filtering is applied to the single-pixel-wide seams between each block.

    It's equivalent to doing a nearest neighbor upscale to floor(scale), then finishing with bilinear.

  • by esafak on 5/2/24, 9:01 PM

    There was a shareware site popular with the photo enthusiasts twenty years ago that implemented numerous resizing algorithms and allowed you to compare them visually. Unfortunately I can not recall its name.
  • by deadbabe on 5/2/24, 2:53 PM

    AI based interpolation will soon make these mathematical interpolation methods obsolete right?