4

Does anyone know the equation/algorithm/theorem used by MATLAB's 'box' interpolation kernel in the imresize function? Or (even better) know a numpy equivelant?

JDeveloper
  • 91
  • 2
  • 11

2 Answers2

3

box interpolation is simply averaging pixels within the specified window size.

You may check the matlab function smooth3 etc for detail.

Xiangrui Li
  • 2,386
  • 2
  • 13
  • 17
  • For me it looks like `box` is equivalent to `nearest`. I guess, the kernel can be defined as `box = @(h) -0.5 < h & h <= 0.5;`. – John Jan 10 '22 at 09:47
0

A "box" kernel is an averaging kernel with uniform weights. If it is an interpolation kernel, then it corresponds to nearest neighbor interpolation (it always takes the average of one input sample).

A bit of theory: an interpolating kernel is one that has a value of 1 at the origin, and a value of 0 at integer distances from the origin. In between it can do different things. Thus, to make from "box" an interpolating kernel, we'd make its width somewhere in between infinitesimally thin and just under 2 sample spacings. That makes it fit the definition of an interpolating kernel. However, if it is thinner than 1 sample spacing, it will generate an output of 0 for some displacements -- not desirable. And if it is wider than 1 sample spacing, there will be displacements where the output is the addition of two input samples, twice as large as it should be -- not desirable either. Thus, making it exactly 1 sample spacing wide is the only useful width here. With this width, at any displacement it always covers exactly one input sample -- hence it does linear interpolation.

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120