This commit is contained in:
nuknal
2024-10-29 16:45:28 +08:00
parent 9c2d93dff4
commit 0e920ce9f0
10 changed files with 57 additions and 57 deletions

View File

@@ -45,20 +45,20 @@ var procCmd = &cobra.Command{
calculator.EOP = calculator.NewEOPTable()
calculator.EOP.Load(eopData, eopp5Line)
reg := producer.NewRegistrator(producer.DownSampled)
reg.Params = initParams()
processor := producer.NewImgProc(producer.DownSampled)
processor.Params = initParams()
if err := reg.LoadAuxData(); err != nil {
if err := processor.LoadAuxData(); err != nil {
logrus.Fatal(err)
}
// reg.AuxPrint()
if err := reg.LoadMssRaw(); err != nil {
if err := processor.LoadMssRaw(); err != nil {
logrus.Fatal(err)
}
if err := reg.LoadPanRaw(); err != nil {
if err := processor.LoadPanRaw(); err != nil {
logrus.Fatal(err)
}
@@ -71,14 +71,14 @@ var procCmd = &cobra.Command{
os.MkdirAll(params.OutputDir, 0755)
if doLUTRRC {
reg.DoRRCbyLUT(lutDir)
processor.DoRRCbyLUT(lutDir)
}
if doMomentMatching {
reg.DoMomentMatching()
processor.DoMomentMatching()
}
if err := reg.DoPhaseCorrelation(); err != nil {
if err := processor.DoPhaseCorrelation(); err != nil {
logrus.Fatal(err)
}
@@ -87,33 +87,33 @@ var procCmd = &cobra.Command{
params.OutputDir,
strings.TrimSuffix(filepath.Base(params.MssRawFile), filepath.Ext(params.MssRawFile))+"_registered.RAW",
)
reg.SaveRegisteredMssToRaw(registerdMSSRAW)
processor.SaveRegisteredMssToRaw(registerdMSSRAW)
}
runtime.GC()
panScenes, mssScenes, err := reg.SubScenes()
panScenes, mssScenes, err := processor.SubScenes()
if err != nil {
logrus.Error(err)
}
reg.OutputL1A(panScenes, mssScenes)
processor.OutputL1A(panScenes, mssScenes)
producer.CleanScenes(panScenes)
producer.CleanScenes(mssScenes)
runtime.GC()
if saveStrip {
reg.SaveOriginalPanToGDALGTiff(reg.Params.PanTiffFile)
reg.SaveRegisteredMssToGDALGTiff(reg.Params.MssTiffFile)
processor.SaveOriginalPanToGDALGTiff(processor.Params.PanTiffFile)
processor.SaveRegisteredMssToGDALGTiff(processor.Params.MssTiffFile)
}
if reg.Params.DoPansharpen {
reg.DoScenePansharpen(panScenes, mssScenes)
if processor.Params.DoPansharpen {
processor.DoScenePansharpen(panScenes, mssScenes)
}
reg.Report()
processor.Report()
reg.Clean()
processor.Clean()
},
}

View File

@@ -21,7 +21,7 @@ import (
"starwiz.cn/sjy01/image-proc/pkg/config"
)
func (r *Registrator) LoadAuxData() error {
func (r *ImgProc) LoadAuxData() error {
var err error
r.auxHeads, r.auxBoxes, r.AuxPlatforms, err = auxilary.ExtractAux(r.Params.AuxRawFile)
@@ -37,7 +37,7 @@ func (r *Registrator) LoadAuxData() error {
}
// 数据校验和测试
func (r *Registrator) AuxPrint() {
func (r *ImgProc) AuxPrint() {
var fcPos84 geojson.FeatureCollection
var fcPos84Interp geojson.FeatureCollection
for _, p := range r.AuxPlatforms {
@@ -63,7 +63,7 @@ func (r *Registrator) AuxPrint() {
f.Write(data)
}
func (r *Registrator) SceneImageTime(scene *Scene) (start, center, end time.Time) {
func (r *ImgProc) SceneImageTime(scene *Scene) (start, center, end time.Time) {
startPosInAux, endPosInAux := r.SceneInAuxIndex(scene)
centerPosInAux := (startPosInAux + endPosInAux) / 2
@@ -78,7 +78,7 @@ func (r *Registrator) SceneImageTime(scene *Scene) (start, center, end time.Time
}
// FIXME: This function is not accurate enough. 四元数、成像时刻、GPS 等需要修改为插值获取
func (r *Registrator) ComputeMetaAndRPC(scene *Scene) (topLeft, bottomRight orb.Point) {
func (r *ImgProc) ComputeMetaAndRPC(scene *Scene) (topLeft, bottomRight orb.Point) {
log.Info("using attitude quaternion to calculate image boundary...")
line0Start := r.calculateLatLonH(scene, 0, 0, 0)
line0End := r.calculateLatLonH(scene, 0, scene.Width, 0)
@@ -169,13 +169,13 @@ func (r *Registrator) ComputeMetaAndRPC(scene *Scene) (topLeft, bottomRight orb.
return
}
func (r *Registrator) SceneInAuxIndex(scene *Scene) (int, int) {
func (r *ImgProc) SceneInAuxIndex(scene *Scene) (int, int) {
startPosInAux := r.sceneOffsetInAuxIndex(scene, 0)
endPosInAux := r.sceneOffsetInAuxIndex(scene, scene.Height)
return startPosInAux, endPosInAux
}
func (r *Registrator) sceneOffsetInAuxIndex(scene *Scene, offset int) int {
func (r *ImgProc) sceneOffsetInAuxIndex(scene *Scene, offset int) int {
var auxForImageRow int
switch scene.Type {
case "MSS":
@@ -194,7 +194,7 @@ func (r *Registrator) sceneOffsetInAuxIndex(scene *Scene, offset int) int {
}
// row, col 相对于图像景左上角, H 为地面目标点高度
func (r *Registrator) calculateLatLonH(scene *Scene, row, col, H int) calculator.IntersectionPoint {
func (r *ImgProc) calculateLatLonH(scene *Scene, row, col, H int) calculator.IntersectionPoint {
// 内插值获取图像行时刻
ucam := col
cross := 16

View File

@@ -1,11 +1,11 @@
package producer
const (
DarkBiasValue = 15675.0/6
DarkBiasValue = 15675.0 / 6
)
// 暗场偏置校正 固定值15675校正
func (r *Registrator) DoDarkBiasCorrection() {
func (r *ImgProc) DoDarkBiasCorrection() {
r.PanImage.SubtractFloat(DarkBiasValue)
for i := 0; i < len(r.registeredMssImages); i++ {
r.registeredMssImages[i].SubtractFloat(DarkBiasValue)

View File

@@ -37,7 +37,7 @@ const (
type ResampleMethod string
type Registrator struct {
type ImgProc struct {
Params Params
PanImage gocv.Mat
@@ -69,14 +69,14 @@ type Registrator struct {
report Report
}
func NewRegistrator(rsmethod ResampleMethod) *Registrator {
var r Registrator
func NewImgProc(rsmethod ResampleMethod) *ImgProc {
var r ImgProc
r.resampleMethod = rsmethod
return &r
}
func (r *Registrator) LoadPanRaw() error {
func (r *ImgProc) LoadPanRaw() error {
data, err := os.ReadFile(r.Params.PanRawFile)
if err != nil {
log.Error("Error reading raw file: ", err)
@@ -111,7 +111,7 @@ func (r *Registrator) LoadPanRaw() error {
return nil
}
func (r *Registrator) LoadMssRaw() error {
func (r *ImgProc) LoadMssRaw() error {
data, err := os.ReadFile(r.Params.MssRawFile)
if err != nil {
log.Error("Error reading raw file: ", err)
@@ -141,7 +141,7 @@ func (r *Registrator) LoadMssRaw() error {
return nil
}
func (r *Registrator) DoPhaseCorrelation() error {
func (r *ImgProc) DoPhaseCorrelation() error {
switch r.resampleMethod {
case UpSampled:
return r.CalcUpPhaseCorrelation()
@@ -151,7 +151,7 @@ func (r *Registrator) DoPhaseCorrelation() error {
}
// 将PAN降采样后计算相位相关的偏移量
func (r *Registrator) CalcDownPhaseCorrelation() error {
func (r *ImgProc) CalcDownPhaseCorrelation() error {
// 确保 MSS 高度是 PAN 高度的 1/4
if r.MssHeight*4 != r.PanHeight {
err := fmt.Errorf("MSS height is not 1/4 of PAN height, invalid raw file")
@@ -209,7 +209,7 @@ func (r *Registrator) CalcDownPhaseCorrelation() error {
}
// 将MSS升采样采样后计算相位相关的偏移量
func (r *Registrator) CalcUpPhaseCorrelation() error {
func (r *ImgProc) CalcUpPhaseCorrelation() error {
log.Fatal("unsuppotted up-resample method")
// 确保 MSS 高度是 PAN 高度的 1/4
if r.MssHeight*4 != r.PanHeight {
@@ -249,7 +249,7 @@ func (r *Registrator) CalcUpPhaseCorrelation() error {
return r.DoPANCoRegistration()
}
func (r *Registrator) doPhaseCorrelation(base gocv.Mat,
func (r *ImgProc) doPhaseCorrelation(base gocv.Mat,
mssImages []gocv.Mat,
height, width,
blockHeight, blockWidth int) error {
@@ -327,7 +327,7 @@ func (r *Registrator) doPhaseCorrelation(base gocv.Mat,
return nil
}
func (r *Registrator) Clean() {
func (r *ImgProc) Clean() {
r.PanImage.Close()
for i := 0; i < MssBands; i++ {
r.MssImages[i].Close()
@@ -340,7 +340,7 @@ func (r *Registrator) Clean() {
r.rgbirImage.Close()
}
func (r *Registrator) calcMSSDeltaCoeffs(bands int) error {
func (r *ImgProc) calcMSSDeltaCoeffs(bands int) error {
// 计算每个通道的delta多项式拟合系数
for i := 0; i < bands; i++ {
var cx []float64
@@ -397,7 +397,7 @@ func (r *Registrator) calcMSSDeltaCoeffs(bands int) error {
return nil
}
func (r *Registrator) DoMSSCoRegistration(byEdge bool) error {
func (r *ImgProc) DoMSSCoRegistration(byEdge bool) error {
for band := 0; band < MssBands; band++ {
if len(r.deltaXCoeffs[band]) < 2 || len(r.deltaYCoeffs[band]) < 3 {
log.Errorf("delta coefficients not calculated, skip co-registration %d", band+1)
@@ -456,7 +456,7 @@ func (r *Registrator) DoMSSCoRegistration(byEdge bool) error {
return nil
}
func (r *Registrator) DoPANCoRegistration() error {
func (r *ImgProc) DoPANCoRegistration() error {
if len(r.deltaXCoeffs[0]) < 2 || len(r.deltaYCoeffs[0]) < 3 {
log.Error("delta coefficients not calculated, skip co-registration")
return nil

View File

@@ -72,7 +72,7 @@ func (corners Corners) Extend() (lng1, lat1, lng2, lat2 float64) {
return
}
func (r *Registrator) makeProductMeta(scene *Scene) *ProductMeta {
func (r *ImgProc) makeProductMeta(scene *Scene) *ProductMeta {
meta := &ProductMeta{
Satellite: "SJY01",
Sensor: "PMS",

View File

@@ -13,7 +13,7 @@ import (
"starwiz.cn/sjy01/image-proc/pkg/utils"
)
func (r *Registrator) SaveOriginalPanToGDALGTiff(tiffFile string) error {
func (r *ImgProc) SaveOriginalPanToGDALGTiff(tiffFile string) error {
err := utils.SavePanToGDALGTiff(r.PanImage, 0, 0, tiffFile, PanResolution)
if err != nil {
return err
@@ -22,7 +22,7 @@ func (r *Registrator) SaveOriginalPanToGDALGTiff(tiffFile string) error {
return nil
}
func (r *Registrator) SaveRegisteredMssToGDALGTiff(tiffFile string) error {
func (r *ImgProc) SaveRegisteredMssToGDALGTiff(tiffFile string) error {
r.rgbirImage = gocv.NewMat()
gocv.Merge(r.registeredMssImages[:], &r.rgbirImage)
@@ -37,7 +37,7 @@ func (r *Registrator) SaveRegisteredMssToGDALGTiff(tiffFile string) error {
return nil
}
func (r *Registrator) BytesToRaw(mssData []byte, filePath string) error {
func (r *ImgProc) BytesToRaw(mssData []byte, filePath string) error {
f, err := os.OpenFile(filePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0777)
if err != nil {
return err
@@ -48,15 +48,15 @@ func (r *Registrator) BytesToRaw(mssData []byte, filePath string) error {
return nil
}
func (r *Registrator) SaveRegisteredMssToRaw(raw string) error {
func (r *ImgProc) SaveRegisteredMssToRaw(raw string) error {
return saveRegisteredMssToRaw(raw, r.registeredMssImages)
}
func (r *Registrator) Report() error {
func (r *ImgProc) Report() error {
return WriteReport(&r.report, r.Params.ReportFile)
}
func (r *Registrator) rpcKeywordInTif() {
func (r *ImgProc) rpcKeywordInTif() {
// GDAL库对应的RPC关键词
// keys := []string{
// "ERR_BIAS", "ERR_RAND",

View File

@@ -22,7 +22,7 @@ type Block struct {
coord image.Point // top-left corner of the block in the original image
}
func (r *Registrator) calculateBlockPhaseShift(panBlock, mssBlock gocv.Mat) (gocv.Point2f, float64) {
func (r *ImgProc) calculateBlockPhaseShift(panBlock, mssBlock gocv.Mat) (gocv.Point2f, float64) {
pan := gocv.NewMat()
mss := gocv.NewMat()
@@ -43,7 +43,7 @@ func (r *Registrator) calculateBlockPhaseShift(panBlock, mssBlock gocv.Mat) (goc
return shift, response
}
func (r *Registrator) fileterPhaseShift(thredholds []float64, greaterThan bool) error {
func (r *ImgProc) fileterPhaseShift(thredholds []float64, greaterThan bool) error {
if len(thredholds) > 4 {
return errors.New("thredholds length should be less than 4")
}

View File

@@ -32,7 +32,7 @@ type RPC struct {
gridsize int
scene *Scene
registrator *Registrator
registrator *ImgProc
}
// GroundPoint 表示地面点的三维坐标
@@ -53,7 +53,7 @@ type RPCModel struct {
}
// rational polynomial coeffients
func NewRPC(r *Registrator, scene *Scene) *RPC {
func NewRPC(r *ImgProc, scene *Scene) *RPC {
rpc := RPC{
elevationLayer: config.GCONFIG.RPC.AltitudeLayer,
gridsize: config.GCONFIG.RPC.GridSize,

View File

@@ -9,7 +9,7 @@ import (
"starwiz.cn/sjy01/image-proc/pkg/rrc"
)
func (r *Registrator) DoRRCbyLUT(lutDir string) error {
func (r *ImgProc) DoRRCbyLUT(lutDir string) error {
logrus.Printf("try to do RRC [%s]...", lutDir)
lutPAN, err := rrc.LoadLUT(filepath.Join(lutDir, "B0.LUT"), 9344)
if err != nil {
@@ -42,7 +42,7 @@ func (r *Registrator) DoRRCbyLUT(lutDir string) error {
return nil
}
func (r *Registrator) DoMomentMatching() error {
func (r *ImgProc) DoMomentMatching() error {
rrc.DoMomentMatching(r.PanImage)
for i := 0; i < 4; i++ {
rrc.DoMomentMatching(r.MssImages[i])

View File

@@ -50,7 +50,7 @@ func CleanScenes(scenes []*Scene) {
// 默认分景大小:
// MSS 2336 * 2336 - 1764
// PAN 9344 * 9344 - 7056
func (r *Registrator) SubScenes() (panScenes []*Scene, mssScenes []*Scene, err error) {
func (r *ImgProc) SubScenes() (panScenes []*Scene, mssScenes []*Scene, err error) {
if len(r.Params.Targets.Targets) > 0 && r.Params.Targets.Targets[0].EndLine > 0 {
return r.RoiScenes()
}
@@ -159,7 +159,7 @@ func (r *Registrator) SubScenes() (panScenes []*Scene, mssScenes []*Scene, err e
return panScenes, mssScenes, err
}
func (r *Registrator) OutputL1A(panScenes []*Scene, mssScenes []*Scene) error {
func (r *ImgProc) OutputL1A(panScenes []*Scene, mssScenes []*Scene) error {
var fc geojson.FeatureCollection
for i, scene := range panScenes {
dir := filepath.Join(r.Params.OutputDir, scene.SceneIndex, "PAN")
@@ -247,7 +247,7 @@ func (r *Registrator) OutputL1A(panScenes []*Scene, mssScenes []*Scene) error {
return nil
}
func (r *Registrator) DoScenePansharpen(panScenes []*Scene, mssScenes []*Scene) error {
func (r *ImgProc) DoScenePansharpen(panScenes []*Scene, mssScenes []*Scene) error {
for i := 0; i < len(panScenes); i++ {
fusedTiff := strings.Replace(mssScenes[i].Tiff, "MSS", "FUS", -1)
err := fusion.Pansharpen(panScenes[i].Tiff, mssScenes[i].Tiff, fusedTiff, fusion.ESRI, 0.1)
@@ -266,7 +266,7 @@ func (r *Registrator) DoScenePansharpen(panScenes []*Scene, mssScenes []*Scene)
return nil
}
func (r *Registrator) MergeMSSToBGRNIR(channels []gocv.Mat) (gocv.Mat, error) {
func (r *ImgProc) MergeMSSToBGRNIR(channels []gocv.Mat) (gocv.Mat, error) {
var rgbirImage gocv.Mat
if len(channels) != 4 {
return rgbirImage, fmt.Errorf("mss channels count not match")
@@ -281,7 +281,7 @@ func (r *Registrator) MergeMSSToBGRNIR(channels []gocv.Mat) (gocv.Mat, error) {
}
func (r *Registrator) RoiScenes() (panScenes []*Scene, mssScenes []*Scene, err error) {
func (r *ImgProc) RoiScenes() (panScenes []*Scene, mssScenes []*Scene, err error) {
log.Println("using target scenes")
for _, target := range r.Params.Targets.Targets {
y0 := 4 * target.StartLine