diff --git a/pkg/calculator/camera.go b/pkg/calculator/camera.go index ee87d1f..334b582 100644 --- a/pkg/calculator/camera.go +++ b/pkg/calculator/camera.go @@ -4,15 +4,16 @@ import ( "math" "gonum.org/v1/gonum/mat" + "starwiz.cn/sjy01/image-proc/pkg/payload" ) const ( FocalLength = 1300.0 // 焦距, mm FOV = 1.7 // 对角线视场角,degree FOVCALC = 1.86 // 对角线视场角,degree - PANPixels = 9344.0 + PANPixels = float64(payload.PAN_PIXEL_WIDTH) PANCellSize = 3.2 // µm - MSSPixels = 2336.0 + MSSPixels = float64(payload.MSS_PIXEL_WIDTH) MSSCellSize = 12.8 // µm CameraRoll = 0.0 // 相机与卫星本体X轴的安装角度, degree FIXME: 安装矩阵应该由卫星方提供 CameraPitch = 0.5 // 相机与卫星本体Y轴的安装角度, degree diff --git a/pkg/config/config.go b/pkg/config/config.go index 7047cfd..021b45d 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -1,6 +1,9 @@ package config -import "github.com/sirupsen/logrus" +import ( + "github.com/sirupsen/logrus" + "starwiz.cn/sjy01/image-proc/pkg/payload" +) type Config struct { CoRegistration CoRegistrationConfig `yaml:"coregistration" mapstructure:"coregistration"` @@ -38,8 +41,8 @@ func init() { CoRegistration: CoRegistrationConfig{ MssBands: 4, PixelBytes: 2, - PanWidth: 9344, - MssWidth: 2336, + PanWidth: payload.PAN_PIXEL_WIDTH, + MssWidth: payload.MSS_PIXEL_WIDTH, OverlappedBlockLines: 3000, CRBlockNW: 8, CRBlockNH: 4, diff --git a/pkg/producer/aux.go b/pkg/producer/aux.go index 5623e63..cdb2f50 100644 --- a/pkg/producer/aux.go +++ b/pkg/producer/aux.go @@ -17,6 +17,7 @@ import ( "github.com/paulmach/orb/planar" "starwiz.cn/sjy01/image-proc/pkg/auxilary" "starwiz.cn/sjy01/image-proc/pkg/calculator" + "starwiz.cn/sjy01/image-proc/pkg/payload" "starwiz.cn/sjy01/image-proc/pkg/utils" ) @@ -133,11 +134,11 @@ func (r *Registrator) SetSceneBoundary(scene *Scene) (topLeft, bottomRight orb.P log.Info("using attitude quaternion to calculate image boundary...") Qsat2eci := calculator.Quaternion{W: as.QuatAttstarQ0, X: as.QuatAttstarQ1, Y: as.QuatAttstarQ2, Z: as.QuatAttstarQ3} line0Start, _ := calculator.IntersectionAttitude(Qsat2eci, startPos84, startTime, 0) - line0End, _ := calculator.IntersectionAttitude(Qsat2eci, startPos84, startTime, 9344) + line0End, _ := calculator.IntersectionAttitude(Qsat2eci, startPos84, startTime, payload.PAN_PIXEL_WIDTH) Qsat2eci = calculator.Quaternion{W: ae.QuatAttstarQ0, X: ae.QuatAttstarQ1, Y: ae.QuatAttstarQ2, Z: ae.QuatAttstarQ3} lineNStart, _ := calculator.IntersectionAttitude(Qsat2eci, endPos84, endTime, 0) - lineNEnd, _ := calculator.IntersectionAttitude(Qsat2eci, endPos84, endTime, 9344) + lineNEnd, _ := calculator.IntersectionAttitude(Qsat2eci, endPos84, endTime, payload.PAN_PIXEL_WIDTH) // ------------------ 使用本体和轨道四元数计算图像边界 ECI------------------ // log.Info("using orbit and body quaternion to calculate image boundary...") @@ -146,14 +147,14 @@ func (r *Registrator) SetSceneBoundary(scene *Scene) (topLeft, bottomRight orb.P // Qorbit2eci := calculator.Quaternion{X: as.QuatOrbJQ1, Y: as.QuatOrbJQ2, Z: as.QuatOrbJQ3} // Qorbit2eci.W = math.Sqrt(1 - Qorbit2eci.X*Qorbit2eci.X - Qorbit2eci.Y*Qorbit2eci.Y - Qorbit2eci.Z*Qorbit2eci.Z) // line0Start,_ := calculator.IntersectionECI(Qsat2orbit, Qorbit2eci, startPos84, startTime, 0) - // line0End,_ := calculator.IntersectionECI(Qsat2orbit, Qorbit2eci, startPos84, startTime, 9344) + // line0End,_ := calculator.IntersectionECI(Qsat2orbit, Qorbit2eci, startPos84, startTime, payload.PAN_PIXEL_WIDTH) // Qsat2orbit = calculator.Quaternion{X: ae.QuatOrbitQ1, Y: ae.QuatOrbitQ2, Z: ae.QuatOrbitQ3} // Qsat2orbit.W = math.Sqrt(1 - Qsat2orbit.X*Qsat2orbit.X - Qsat2orbit.Y*Qsat2orbit.Y - Qsat2orbit.Z*Qsat2orbit.Z) // Qorbit2eci = calculator.Quaternion{X: ae.QuatOrbJQ1, Y: ae.QuatOrbJQ2, Z: ae.QuatOrbJQ3} // Qorbit2eci.W = math.Sqrt(1 - Qorbit2eci.X*Qorbit2eci.X - Qorbit2eci.Y*Qorbit2eci.Y - Qorbit2eci.Z*Qorbit2eci.Z) // lineNStart,_ := calculator.IntersectionECI(Qsat2orbit, Qorbit2eci, endPos84, endTime, 0) - // lineNEnd,_ := calculator.IntersectionECI(Qsat2orbit, Qorbit2eci, endPos84, endTime, 9344) + // lineNEnd,_ := calculator.IntersectionECI(Qsat2orbit, Qorbit2eci, endPos84, endTime, payload.PAN_PIXEL_WIDTH) // ------------------ 使用本体和轨道四元数计算图像边界 ECEF------------------ // log.Info("using orbit and body quaternion to calculate image boundary...") @@ -161,13 +162,13 @@ func (r *Registrator) SetSceneBoundary(scene *Scene) (topLeft, bottomRight orb.P // Qsat2orbit.W = math.Sqrt(1 - Qsat2orbit.X*Qsat2orbit.X - Qsat2orbit.Y*Qsat2orbit.Y - Qsat2orbit.Z*Qsat2orbit.Z) // vec84 := []float64{as.W84VelX, as.W84VelY, as.W84VelZ} // line0Start, _ := calculator.IntersectionECEF(Qsat2orbit, startPos84, vec84, 0) - // line0End, _ := calculator.IntersectionECEF(Qsat2orbit, startPos84, vec84, 9344) + // line0End, _ := calculator.IntersectionECEF(Qsat2orbit, startPos84, vec84, payload.PAN_PIXEL_WIDTH) // Qsat2orbit = calculator.Quaternion{X: ae.QuatOrbitQ1, Y: ae.QuatOrbitQ2, Z: ae.QuatOrbitQ3} // Qsat2orbit.W = math.Sqrt(1 - Qsat2orbit.X*Qsat2orbit.X - Qsat2orbit.Y*Qsat2orbit.Y - Qsat2orbit.Z*Qsat2orbit.Z) // vec84 = []float64{ae.W84VelX, ae.W84VelY, ae.W84VelZ} // lineNStart, _ := calculator.IntersectionECEF(Qsat2orbit, endPos84, vec84, 0) - // lineNEnd, _ := calculator.IntersectionECEF(Qsat2orbit, endPos84, vec84, 9344) + // lineNEnd, _ := calculator.IntersectionECEF(Qsat2orbit, endPos84, vec84, payload.PAN_PIXEL_WIDTH) // ------------------ 计算图像边界距离和分辨率 ------------------ W0 := geo.Distance(orb.Point{line0Start.Lon, line0Start.Lat}, orb.Point{line0End.Lon, line0End.Lat}) diff --git a/pkg/producer/image_registration.go b/pkg/producer/image_registration.go index 0b78c16..5f74c17 100644 --- a/pkg/producer/image_registration.go +++ b/pkg/producer/image_registration.go @@ -14,6 +14,7 @@ import ( "gonum.org/v1/gonum/interp" "gonum.org/v1/gonum/spatial/r3" "starwiz.cn/sjy01/image-proc/pkg/auxilary" + "starwiz.cn/sjy01/image-proc/pkg/payload" ) type Registrate interface{} @@ -21,8 +22,8 @@ type Registrate interface{} const ( MssBands = 4 PixelBytes = 2 - PanWidth = 9344 // 像素宽度 - MssWidth = 2336 + PanWidth = payload.PAN_PIXEL_WIDTH // 像素宽度 + MssWidth = payload.MSS_PIXEL_WIDTH BlockNH = 4 BlockNW = 8 OverlappedBlockLines = 3000 // 重叠块的行数 diff --git a/pkg/producer/rrc.go b/pkg/producer/rrc.go index 11d9e1d..016dd19 100644 --- a/pkg/producer/rrc.go +++ b/pkg/producer/rrc.go @@ -5,6 +5,7 @@ import ( "path/filepath" "github.com/sirupsen/logrus" + "starwiz.cn/sjy01/image-proc/pkg/payload" "starwiz.cn/sjy01/image-proc/pkg/rrc" ) @@ -24,7 +25,7 @@ func (r *Registrator) DoRRCbyLUT(lutDir string) error { } for i := 0; i < 4; i++ { - lutMSS, err := rrc.LoadLUT(filepath.Join(lutDir, fmt.Sprintf("B%d.LUT", i+1)), 2336) + lutMSS, err := rrc.LoadLUT(filepath.Join(lutDir, fmt.Sprintf("B%d.LUT", i+1)), payload.MSS_PIXEL_WIDTH) if err != nil { logrus.Error("load mss gray table failed") return err diff --git a/pkg/producer/scenes.go b/pkg/producer/scenes.go index d0e9f2b..3a1d9a9 100644 --- a/pkg/producer/scenes.go +++ b/pkg/producer/scenes.go @@ -14,6 +14,7 @@ import ( log "github.com/sirupsen/logrus" "gocv.io/x/gocv" "starwiz.cn/sjy01/image-proc/pkg/config" + "starwiz.cn/sjy01/image-proc/pkg/payload" "starwiz.cn/sjy01/image-proc/pkg/rrc" "starwiz.cn/sjy01/image-proc/pkg/utils" ) @@ -47,8 +48,8 @@ func CleanScenes(scenes []*Scene) { // MSS 2336 * 2336 - 1764 // PAN 9344 * 9344 - 7056 func (r *Registrator) SubScenes() (panScenes []*Scene, mssScenes []*Scene, err error) { - hPAN := (9344 - 2336) - hPANOverlap := 2336 + hPAN := (payload.PAN_PIXEL_WIDTH - payload.MSS_PIXEL_WIDTH) + hPANOverlap := payload.MSS_PIXEL_WIDTH panScenesCnt := r.PanHeight / hPAN for i := 0; i <= panScenesCnt; i++ { @@ -59,7 +60,7 @@ func (r *Registrator) SubScenes() (panScenes []*Scene, mssScenes []*Scene, err e scene := &Scene{ Type: "PAN", - Width: 9344, + Width: payload.PAN_PIXEL_WIDTH, Height: y1 - i*hPAN, X: 0, Y: i * hPAN, @@ -74,7 +75,7 @@ func (r *Registrator) SubScenes() (panScenes []*Scene, mssScenes []*Scene, err e name = strings.TrimSuffix(name, ".tiff") scene.SceneId = fmt.Sprintf("%s_%03d", name, i+1) - mat := r.PanImage.Region(image.Rect(0, i*hPAN, 9344, y1)) + mat := r.PanImage.Region(image.Rect(0, i*hPAN, payload.PAN_PIXEL_WIDTH, y1)) if config.GCONFIG.Radiation.PANRemoveHfNoise { log.Println("applying hf noise filter on", scene.SceneId) matFiltered := rrc.HFNoiseFilter(mat, float64(mat.Cols())*config.GCONFIG.Radiation.HfRadiusRatio) @@ -101,7 +102,7 @@ func (r *Registrator) SubScenes() (panScenes []*Scene, mssScenes []*Scene, err e scene := &Scene{ Type: "MSS", - Width: 2336, + Width: payload.MSS_PIXEL_WIDTH, Height: y1 - i*hMSS, X: 0, Y: i * hMSS, diff --git a/pkg/rrc/filter_test.go b/pkg/rrc/filter_test.go index 7b7d801..03d123d 100644 --- a/pkg/rrc/filter_test.go +++ b/pkg/rrc/filter_test.go @@ -6,6 +6,7 @@ import ( "github.com/airbusgeo/godal" "gocv.io/x/gocv" + "starwiz.cn/sjy01/image-proc/pkg/payload" "starwiz.cn/sjy01/image-proc/pkg/utils" ) @@ -53,8 +54,8 @@ func TestMomentMatching(t *testing.T) { t.Error(err) } - height := len(data) / (9344 * 2) - img, err := gocv.NewMatFromBytes(height, 9344, gocv.MatTypeCV16U, data) + height := len(data) / (payload.PAN_PIXEL_WIDTH * 2) + img, err := gocv.NewMatFromBytes(height, payload.PAN_PIXEL_WIDTH, gocv.MatTypeCV16U, data) if err != nil { t.Error(err) } diff --git a/pkg/rrc/rrc.go b/pkg/rrc/rrc.go index 3cf42fc..9154f4d 100644 --- a/pkg/rrc/rrc.go +++ b/pkg/rrc/rrc.go @@ -10,6 +10,7 @@ import ( log "github.com/sirupsen/logrus" "gocv.io/x/gocv" + "starwiz.cn/sjy01/image-proc/pkg/payload" "starwiz.cn/sjy01/image-proc/pkg/utils" ) @@ -17,9 +18,9 @@ import ( // 采用在轨统计定标方法。利用卫星在轨后获取的常规影像数据,统计每个探元出现的灰度频次。 const ( - PANCameraProbeNum = 9344 // 全色探元数 - MSSCameraProbeNum = 2336 // 多光谱探元数 - MaxGrayLevel = 65536 // 16bit像素值 + PANCameraProbeNum = payload.PAN_PIXEL_WIDTH // 全色探元数 + MSSCameraProbeNum = payload.MSS_PIXEL_WIDTH // 多光谱探元数 + MaxGrayLevel = 65536 // 16bit像素值 ) type RRC struct {