I want to estimate a nonlinear mapping from two-dimensional input positions to two-dimensional output positions. (Think of this as a nonlinear distortion of an image. Once I get the estimated function, I can use ImageForwardTransformation
to perform the transformation on the full image.)
Suppose I have $n$ pairs of "training points": input $(x_i, y_i)$ to corresponding output $(x_i^\prime , y_i^\prime)$ for $i = 1, \ldots n$.
As a minimum-working example, assume the following two-dimensional data with $n=5$:
input = {{0, 0}, {1, 1}, {2, 3}, {2, 4}, {3, 2}};
output = {{0, 0}, {1, 2}, {2, 2}, {3, 2.5}, {4, 3}};
The direct approach to learning the transformation function would be to use NonlinearModelFit
with (say) different quadratic functions for each of the coordinates. That is, learn two functions $(x_i^\prime, y_i^\prime) = (f_1(x_i, y_i), f_2(x_i, y_i))$. The problem is that this approach doesn't adequately incorporate the fact that in the desired true mapping the coordinate mappings are not independent.
What I think we really need is to estimate a single mapping function from two-dimensional input to two-dimensional output.
Alas, I just couldn't figure out the syntax in NonlinearModelFit
to achieve this (and apply it to my above sample data). I have a feeling I'm overlooking some subtlety of syntax in order to get Mathematica to learn the desired mapping.
Any suggestions?
FindGeometricTransform[output, input]
? $\endgroup$