0
$\begingroup$

For a given 2D surface, I have some points, and I need to interpolate others. For example, in the following picture we have points (x,y,z), where z is represented with the colors you see.

The dots are the known points (where we know their x, y and z values). The ? represents any given point we want to interpolate (because we don't know their z).

For the ? point we know its (x,y) obviously, but we don't know z which needs to be interpolated.

Problem: What is the best way of interpolating a z for point ? from the surrounding points?

enter image description here

  • 0
    I dont see where the problem is. The x,y,z values of dots are known so is the x,y values of ? .2017-02-14
  • 0
    I don't know the value `z` of `?`. How can I interpolate it from the other points?2017-02-14
  • 0
    I edited the post to make the problem more clear.2017-02-14
  • 0
    There is no unique "best" way. You can express the function $f(x,y)$ in a large number of bases (polynomials, wavelets, etc.) and estimate the coefficients. Another simple way is to use a sum of 2D Gaussians centered on the known points. And many others.2017-02-14
  • 0
    The best way to interpolate depends on the application. Sometimes, you can just write down what your goals are, and just *solve* for the best interpolation method.2017-02-14

1 Answers 1

1

There are plenty of methods to interpolate the z value. One of the simplest is the interpolation using k nearest neighbors. For instance find the 3 neirest neighbors of the ? and then calculate the z values according to the z values of its neighbors. To be more specific z value is calculating using a weighted average of the neighbors, the further the neighbor is the smaller the weight. For implementation details check methods bilinear interpolation

I suggest you using the bilinear method since it might be slightly more difficult to implement but results in higher quality image.

  • 0
    I have tried the K nearest neighbors, but I am a hard time calculating the weights using the distance. If I have one neighbor with Z = 10 and other with Z = 20, I might get Z = 22, which is higher than any of the neighbors... I was calculating the weight for each neighbor like this: (1 - (distance / 100)), (the maximum distance possible is 100).2017-02-14
  • 0
    For your example lets say you want to paint Z and you know Z1 and Z2 given that d(Z,Z1)=d1 and d(Z,Z2)=d2 Z=d1/(d1+d2)*Z2+d2/(d1+d2)*Z12017-02-14
  • 0
    Yes, that is very close...! The only issue is that the weight is inversely proportional to the distance. I've tried 1 - (d1/(d1+d2)) and 1/(d1/(d1+d2)) but nothing seems to be right. When I sum all weights I should get 1 but I get 2 when I try to use those two expressions.2017-02-15
  • 0
    @PedroD i dont quite get your second weight. But consider the weights w1=d1/(d1+d2) and w2=d2/(d1+d2). It is obvious that w1+w2=(d1+d2)/(d1+d2)=1. You dont have to inverse the weights. I mean the w1=d2/(d1+d2) is multiplied by the Z1 and the w2=d1/(d1+d2) is multiplied by the Z2.2017-02-15
  • 0
    The thing is, the way you suggest will give more weight to points which are further. The weight should be inversely proportional to the distance. So if d1 is very close to 0, w1 would be maximum compared to w2.2017-02-15
  • 0
    But I don't know how to express this inversion.2017-02-15
  • 0
    not reallly since d1/(d1+d2) is multiplied by the Z2 that is the if d2>d1 then d1/(d1+d2) is smaller than d2/(d1+d2) so Z2 being further has a smaller weight realitive to the Z1 which will be multiplied by the bigger weights d2/(d1+d2) since Z1 is closer to the ? than Z2 .2017-02-15
  • 1
    Ah I see, my bad. I will try to generalize this to N points instead of just two. Thanks!2017-02-15
  • 0
    Being `Total=(d1+d2+d3+...+dn)` I am trying `Z=((Total - d1)/Total) * Z1 + ((Total - d2)/Total) * Z2 + ... + ((Total - dn)/Total) * Zn` but if I sum all the weights I am getting 2 instead of 1... I am so bad at this...2017-02-15
  • 0
    Hmmmmmmmmmmmmmm2017-02-27
  • 0
    make sure to understand Bilinear interpolation. Im pretty sure you will get to solve your problem. To help you a little bit you can calculate the interpolated points in the middle of each pair of duplicate points and then using the 2 middle interpolated colors calculate the color of ?2017-02-27