Weights of linear interpolation in remap function

Hello everyone, I would like understand how weights are computed in remap function when we use linear interpolation?
I tried to use the distance between the warped coordinates and the coordinates of a pixel but I didn’t have the same results as remap.

the xmap and ymap only contain coordinates. these coordinates may be floating point, or they may be a denser fixed point format.

linear interpolation happens inside of remap() and it just does what you’d expect.

please explain what you mean. you have given no debuggable details at all.

please check out How to create a Minimal, Reproducible Example - Help Center - Stack Overflow

Thank you for your answer.
Actually I’am trying to implement a function that gives the same results as remap().

For the example,
Let A be a 2 x 2 matrix
[[70. 80.]
[10. 30.]]
and let c be the array containig the x-coordinates of each pixel.
[[0. 1.]
[0. 1.]]
I want for the example to remap A after substracting 0.3 from the x coordinate of each pixel. So the new map is given by: new_c=c-0.3

When I use the function remap:

[[48.125 76.875]
[ 6.875 23.75 ]]

But I have a diferent results when I use my function, where the weights are computed by computing the distance of the new coordiantes and their nearest neighbors
for the example, the weight used to interpolate the pixel (-0.3,0) is given by 0 -(-0.3)= 0.3
[[49. 77.]
[ 7. 24.]]

How the difference between the results is explained?

remap internally uses fixed point (integer) math, even if you give it floating point maps. that will cause some rounding.

I don’t remember if it’s 4 or 5 fractional bits. if you calculate with 10/32 = 0.3125 = 5/16, do your results agree with remap then?

further, there’s a borderMode that affects how pixels at/over the border are handled.


1 Like

Yes, I had the same results when I use 10/32.