4*4*5
This commit is contained in:
@@ -1,25 +1,27 @@
|
||||
package producer
|
||||
|
||||
import "starwiz.cn/sjy01/image-proc/pkg/config"
|
||||
|
||||
type GridPoint struct {
|
||||
Row, Col, H int
|
||||
}
|
||||
|
||||
// 网格点要覆盖边界,甚至大于边界
|
||||
func gridImage2(m, n, height, width, k, hmin, hmax int) []*GridPoint {
|
||||
a := int((height) / (m + 1))
|
||||
a := int((height) / (m))
|
||||
var lines []int
|
||||
for i := 1; i <= m; i++ {
|
||||
for i := 0; i <= m; i++ {
|
||||
lines = append(lines, a*i)
|
||||
}
|
||||
|
||||
b := int((width) / (n + 1))
|
||||
b := int((width) / (n))
|
||||
var samples []int
|
||||
for i := 1; i <= n; i++ {
|
||||
for i := 0; i <= n; i++ {
|
||||
samples = append(samples, b*i)
|
||||
}
|
||||
|
||||
hmax = hmax + 500
|
||||
hmin = hmin - 500
|
||||
hmax = (hmax+hmin)/2.0 + config.GCONFIG.RPC.AltitudeRange/2
|
||||
hmin = (hmax+hmin)/2.0 - config.GCONFIG.RPC.AltitudeRange/2
|
||||
dh := (hmax - hmin) / (k)
|
||||
|
||||
var h []int
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gonum.org/v1/gonum/mat"
|
||||
"starwiz.cn/sjy01/image-proc/pkg/config"
|
||||
"starwiz.cn/sjy01/image-proc/pkg/dem"
|
||||
)
|
||||
|
||||
@@ -56,8 +57,8 @@ type RPCModel struct {
|
||||
// rational polynomial coeffients
|
||||
func NewRPC(r *Registrator, scene *Scene, rpb string) *RPC {
|
||||
rpc := RPC{
|
||||
elevationLayer: 5,
|
||||
gridsize: 20,
|
||||
elevationLayer: config.GCONFIG.RPC.AltitudeLayer,
|
||||
gridsize: config.GCONFIG.RPC.GridSize,
|
||||
registrator: r,
|
||||
scene: scene,
|
||||
rpb: rpb,
|
||||
@@ -140,22 +141,28 @@ func (rpc *RPC) RPC() error {
|
||||
rpc.saveVec(strings.Replace(rpc.scene.Tiff, ".tiff", ".vec.txt", -1),
|
||||
rowVec, colVec, latVec, lonVec, heightVec)
|
||||
|
||||
rpc.lineOffset = float64(rpc.scene.Height) / 2.0
|
||||
rpc.lineScale = float64(rpc.scene.Height) / 2.0
|
||||
rpc.sampOffset = float64(rpc.scene.Width) / 2.0
|
||||
rpc.sampScale = float64(rpc.scene.Width) / 2.0
|
||||
rowVec = normalize2(rowVec, rpc.lineOffset, rpc.lineScale)
|
||||
colVec = normalize2(colVec, rpc.sampOffset, rpc.sampScale)
|
||||
// rpc.lineOffset = float64(rpc.scene.Height) / 2.0
|
||||
// rpc.lineScale = float64(rpc.scene.Height)
|
||||
// rowVec = normalize2(rowVec, rpc.lineOffset, rpc.lineScale)
|
||||
// rpc.sampOffset = float64(rpc.scene.Width) / 2.0
|
||||
// rpc.sampScale = float64(rpc.scene.Width)
|
||||
// colVec = normalize2(colVec, rpc.sampOffset, rpc.sampScale)
|
||||
// rpc.heightOffset = (rpc.minH + rpc.maxH) / 2.0
|
||||
// rpc.heightScale = 1000.0
|
||||
// heightVec = normalize2(heightVec, rpc.heightOffset, rpc.heightScale)
|
||||
|
||||
latVec, rpc.latOffset, rpc.latScale = normalize(latVec)
|
||||
lonVec, rpc.longOffset, rpc.longScale = normalize(lonVec)
|
||||
heightVec, rpc.heightOffset, rpc.heightScale = normalize(heightVec)
|
||||
rowVec, rpc.lineOffset, rpc.lineScale = normalize(rowVec)
|
||||
colVec, rpc.sampOffset, rpc.sampScale = normalize(colVec)
|
||||
|
||||
rpc.saveVec(strings.Replace(rpc.scene.Tiff, ".tiff", ".vec_norm.txt", -1),
|
||||
rowVec, colVec, latVec, lonVec, heightVec)
|
||||
|
||||
// 设计矩阵 B = [ 20个分子系数 19个分母系数 ] W = 权矩阵 R = 观测结果
|
||||
method := SolveMethodNelderMead
|
||||
|
||||
// x = (B^T * W^2 * B)^-1 * (B^T * W^2 * R), 其中 x = [a1..a20 b2..b20]^T
|
||||
// 行参数
|
||||
// B := setupSystemOfEquations(rowVec, latVec, lonVec, heightVec)
|
||||
|
||||
@@ -58,6 +58,7 @@ func solveCoefficients(f, latVec, lonVec, heightVec *mat.VecDense, method SolveM
|
||||
var MtF mat.VecDense
|
||||
MtF.MulVec(M.T(), f)
|
||||
x0.MulVec(invMtM, &MtF)
|
||||
// return mat.Col(nil, 0, &x0), nil
|
||||
|
||||
if method == SolveMethodNelderMead {
|
||||
numerator := mat.NewVecDense(20, nil)
|
||||
@@ -83,12 +84,10 @@ func solveCoefficients(f, latVec, lonVec, heightVec *mat.VecDense, method SolveM
|
||||
}
|
||||
|
||||
// 迭代
|
||||
var wm mat.Dense
|
||||
var wmx, wf mat.VecDense
|
||||
|
||||
var x1 mat.VecDense
|
||||
|
||||
var vx []*VX
|
||||
v0 := 0.0
|
||||
iterations := 0
|
||||
maxIterations := 10
|
||||
denominator := mat.NewVecDense(20, nil)
|
||||
@@ -113,22 +112,36 @@ func solveCoefficients(f, latVec, lonVec, heightVec *mat.VecDense, method SolveM
|
||||
MtW2F.MulVec(&MtW2, f)
|
||||
x1.MulVec(invMtW2M, &MtW2F)
|
||||
|
||||
wm.Mul(weights, M)
|
||||
wmx.MulVec(&wm, &x1)
|
||||
wf.MulVec(weights, f)
|
||||
wmx.SubVec(&wmx, &wf)
|
||||
wmx.MulElemVec(&wmx, &wmx)
|
||||
v := math.Sqrt(mat.Max(&wmx))
|
||||
log.Println("iteration:", iterations, "v-err:", v)
|
||||
numerator1 := mat.NewVecDense(20, nil)
|
||||
denominator1 := mat.NewVecDense(20, nil)
|
||||
denominator1.SetVec(0, 1.0)
|
||||
numerator1.SetVec(0, x0.AtVec(0))
|
||||
for i := 1; i < 20; i++ {
|
||||
numerator1.SetVec(i, x1.AtVec(i))
|
||||
denominator1.SetVec(i, x1.AtVec(i+19))
|
||||
}
|
||||
|
||||
vx = append(vx, &VX{v: v, x: x1})
|
||||
if math.Abs(v-v0) < epsilon {
|
||||
break
|
||||
errorSquared := 0.0
|
||||
lambda := 1e-4
|
||||
for i := 0; i < n; i++ {
|
||||
predictedV := project(numerator1, denominator1, latVec.AtVec(i), lonVec.AtVec(i), heightVec.AtVec(i))
|
||||
errorV := predictedV - f.AtVec(i)
|
||||
errorSquared += errorV * errorV
|
||||
}
|
||||
fmt.Printf("squared error: %.8f\n", errorSquared)
|
||||
var coeffsSquared float64
|
||||
for i := 0; i < 20; i++ {
|
||||
coeffsSquared += lambda * (numerator1.AtVec(i)*numerator1.AtVec(i) + denominator1.AtVec(i)*denominator1.AtVec(i))
|
||||
}
|
||||
|
||||
x0 = x1
|
||||
v0 = v
|
||||
iterations++
|
||||
|
||||
fmt.Printf("squared error+lambda*coeffs: %.8f\n", coeffsSquared)
|
||||
vx = append(vx, &VX{v: errorSquared, x: x1})
|
||||
if errorSquared < 0.001 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
log.Println("iterations:", iterations)
|
||||
|
||||
@@ -19,6 +19,12 @@ func objectiveFunc(numerator, denominator, f, latVec, lonVec, heightVec *mat.Vec
|
||||
errorV := predictedV - f.AtVec(i)
|
||||
errorSquared += errorV * errorV
|
||||
}
|
||||
// lambda := 1e-2
|
||||
// coeffsSquaredError := 0.0
|
||||
// for i := 0; i < 20; i++ {
|
||||
// coeffsSquaredError += lambda * (numerator.AtVec(i)*numerator.AtVec(i) + denominator.AtVec(i)*denominator.AtVec(i))
|
||||
// }
|
||||
|
||||
return errorSquared
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user