Hmm… It seems to “work”, but I can’t help feeling this can’t be right.
I’m essentially feeding the interpolation knots that are one set of x values per y value, where each respective level of x is very similar across the levels of y:
0.914293 1.12394 0.888184 0.939205 … 0.977576 0.950751 0.878769 0.963788
2.07355 2.05893 2.11997 2.10999 1.91213 1.92552 1.95643 2.00277
2.96772 2.99958 3.07324 3.05772 3.03218 3.0367 3.03536 2.93699
4.10374 3.95213 3.9412 3.99084 4.0744 3.90924 3.913 3.93404
4.92337 5.04418 5.11515 5.03542 4.9369 4.95768 5.06762 5.08227
5.98328 5.95238 6.01513 6.12016 … 6.07736 5.9214 6.0 6.09871
6.93604 7.0379 6.97642 6.94647 7.02528 6.99787 6.95569 7.08504
7.92821 7.91549 8.08373 8.01549 8.06387 8.09904 8.02936 7.89755
8.9328 9.06075 9.022 8.94114 9.05516 8.97034 9.10086 9.03877
9.93574 10.0749 10.016 9.89389 10.0083 9.88933 9.98516 10.1002
and respective points that are identical across the set of y values:
125.0 125.0 125.0 125.0 125.0 125.0 125.0 125.0 125.0 125.0
144.444 144.444 144.444 144.444 144.444 144.444 144.444 144.444 144.444 144.444
163.889 163.889 163.889 163.889 163.889 163.889 163.889 163.889 163.889 163.889
183.333 183.333 183.333 183.333 183.333 183.333 183.333 183.333 183.333 183.333
202.778 202.778 202.778 202.778 202.778 202.778 202.778 202.778 202.778 202.778
222.222 222.222 222.222 222.222 222.222 222.222 222.222 222.222 222.222 222.222
241.667 241.667 241.667 241.667 241.667 241.667 241.667 241.667 241.667 241.667
261.111 261.111 261.111 261.111 261.111 261.111 261.111 261.111 261.111 261.111
280.556 280.556 280.556 280.556 280.556 280.556 280.556 280.556 280.556 280.556
300.0 300.0 300.0 300.0 300.0 300.0 300.0 300.0 300.0 300.0
This seems very wrong because the interpolation is ignorant of what the y value is for each of those columns (and in my case also, what the y value is for each row, simply put, each cell).
Here’s the code I’m using, just to be clear:
using Plots, Interpolations
image_x = [i + (rand()-.5)/4 for i in 1:10, j in 1:10]
image_y = [j + (rand()-.5)/4 for i in 1:10, j in 1:10]
plot(image_x,image_y, marker=:circle,color=:black)
plot!(image_x',image_y',color=:black,legend=false, grid=false)
x_in = [rand(1.5:9.5) + (rand()-.5)/2 for i in 1:10]
y_in = [rand(1.5:9.5) + (rand()-.5)/2 for i in 1:10]
scatter!(x_in,y_in,marker=:circle,color=:red)
png("a1.png")
world_x = linspace(125,300,10)
world_y = linspace(-5,53,10)
knots = vec(image_x)
A = vec(world_x .+ 0world_y')
o = sortperm(knots)
itx = interpolate((knots[o],), A[o], Gridded(Linear()))
knots = vec(image_y)
A = vec(0world_x .+ world_y')
o = sortperm(knots)
ity = interpolate((knots[o],), A[o], Gridded(Linear()))
x_out = itx[x_in]
y_out = ity[y_in]
x = repmat(world_x,1,10)
y = repmat(world_y',10)
plot(x,y, marker=:circle,color=:black)
plot!(x',y',color=:black,legend=false, grid=false)
scatter!(x_out, y_out, marker=:circle,color=:red)
png("a2.png")