This script implements polynomial regression to transform Ground Control Points (GCPs) between image and real-world coordinates. It performs bidirectional mapping:
- Forward Transformation: Maps real-world coordinates ((X, Y)) to image coordinates ((x, y)).
- Backward Transformation: Maps image coordinates ((x, y)) to real-world coordinates ((X, Y)).
The model utilizes polynomial regression of degree (d) and normalizes data before fitting.
To improve numerical stability, data is normalized using mean and standard deviation:
where:
- ( \mu ) is the mean.
- ( \sigma ) is the standard deviation.
The design matrix (A) consists of polynomial basis functions up to a given degree (d):
The number of terms in the polynomial:
For degree (d=2), the design matrix takes the form:
The transformation is modeled as:
where:
- ( A ) and ( A' ) are the design matrices.
- ( c_x, c_y, c_X, c_Y ) are the regression coefficients computed using least squares estimation:
Given a new input ((X, Y)) or ((x, y)), the estimated output is:
Denormalization is applied to restore original values:
The error is measured using Root Mean Square Error (RMSE):