控制点过少时导致图像内畸变较大

This commit is contained in:
nuknal
2024-09-04 17:59:12 +08:00
parent abe5ecbdec
commit df6090df21
3 changed files with 17 additions and 27 deletions

View File

@@ -46,28 +46,18 @@ func normalize2(v *mat.VecDense, vOff, vScale float64) *mat.VecDense {
func solveCoefficients(f, latVec, lonVec, heightVec *mat.VecDense, method SolveMethod) ([]float64, error) {
M := setupSystemOfEquations(f, latVec, lonVec, heightVec)
n := f.Len()
weights := mat.NewDiagDense(n, nil)
for i := 0; i < n; i++ {
weights.SetDiag(i, 1.0)
}
// 计算初始值
// 计算初始值 x = (M^T * M)^-1 * (M^T * f)
var x0 mat.VecDense
w2 := mat.NewDiagDense(n, nil)
for i := 0; i < n; i++ {
w2.SetDiag(i, weights.At(i, i)*weights.At(i, i))
}
var MtW2 mat.Dense
MtW2.Mul(M.T(), w2)
var MtW2M mat.Dense
MtW2M.Mul(&MtW2, M)
invMtW2M, err := invertRPCMatrix(&MtW2M)
var MtM mat.Dense
MtM.Mul(M.T(), M)
invMtM, err := invertRPCMatrix(&MtM)
if err != nil {
return nil, err
}
var MtW2F mat.VecDense
MtW2F.MulVec(&MtW2, f)
x0.MulVec(invMtW2M, &MtW2F)
var MtF mat.VecDense
MtF.MulVec(M.T(), f)
x0.MulVec(invMtM, &MtF)
if method == SolveMethodNelderMead {
numerator := mat.NewVecDense(20, nil)
@@ -102,12 +92,15 @@ func solveCoefficients(f, latVec, lonVec, heightVec *mat.VecDense, method SolveM
iterations := 0
maxIterations := 10
denominator := mat.NewVecDense(20, nil)
w2 := mat.NewDiagDense(n, nil)
var MtW2, MtW2M mat.Dense
var MtW2F mat.VecDense
for iterations < maxIterations {
denominator.SetVec(0, 1.0)
for idx := 1; idx < 20; idx++ {
denominator.SetVec(idx, x0.AtVec(idx+19))
}
weights = setupWeightMatrix(denominator, latVec, lonVec, heightVec)
weights := setupWeightMatrix(denominator, latVec, lonVec, heightVec)
for i := 0; i < n; i++ {
w2.SetDiag(i, weights.At(i, i)*weights.At(i, i))
}