Bilinear interpolation - point outside of the grid

419 Views Asked by At

Suppose I have a 10x10 pixel grid. Assume that each pixel has value 1 (it is not important). Now in the typical case, if I would like to sample a point inside of the grid, for example p1=(0.5,0.5)=(x,y), then we can apply bilinear interpolation by:

Finding x1 by flooring x and x2 = x1+1. x1=0, x2=1

Finding y1 by flooring y and y2 = y2+1 y1=0, y2=1

The resulting values will be a function of the values of the pixels (0,0),(1,0),(0,1),(1,1).

However, suppose now that I have a point outside of the grid. The point p2=(9.5,9.5)=(x,y). Note that as the grid is 0-indexed this point is outside of the grid. What will x1 and y2 be in this case and what will my nearest pixel coordinates be? Do we just change x to the point (9,9) and then perform bilinear interpolation using pixels (8,8),(9,8),(8,9),(9,9)? Or do we perform some kind of padding?

If there are multiple approaches, I am looking for the one that most libraries would use.

1

There are 1 best solutions below

0
On

By definition of bilinear interpolation, you need to take the 4 nearest points whose cell centres are closest to the point, which in this case will be (8,8), (8,9), (9,8) and (9,9). If you do it any other way, or any variation of this definition, you wouldn't be doing bilinear interpolation. If you think about it, it does make sense since there is no way to know anything beyond this point, and so our best guess would be to use the 4 points closest to this point to estimate the value.