ROI produce params

This commit is contained in:
nuknal
2024-07-22 16:56:29 +08:00
parent 688f709b39
commit 814d750f99
3 changed files with 143 additions and 31 deletions

View File

@@ -133,6 +133,7 @@ func initParams() producer.Params {
taskParams.OutputDir = task.Params.OutputPath taskParams.OutputDir = task.Params.OutputPath
taskParams.ReportFile = task.Params.ReportFile taskParams.ReportFile = task.Params.ReportFile
taskParams.DataId = task.Params.DataID taskParams.DataId = task.Params.DataID
taskParams.Targets = task.Params.Targets
} }
taskParams.MssTiffFile = filepath.Join(taskParams.OutputDir, strings.TrimSuffix(filepath.Base(taskParams.MssRawFile), taskParams.MssTiffFile = filepath.Join(taskParams.OutputDir, strings.TrimSuffix(filepath.Base(taskParams.MssRawFile),

View File

@@ -18,6 +18,15 @@ type Params struct {
SubScenes bool SubScenes bool
ReportFile string ReportFile string
DataId string DataId string
Targets ROITargets // 分景的时候优先按目标分景输出_ROI_100_2000_
}
type ROITargets struct {
XMLName xml.Name `xml:"targets"`
Targets []struct {
StartLine int `xml:"startLine"`
EndLine int `xml:"endLine"`
} `xml:"target"`
} }
type XMLImageTask struct { type XMLImageTask struct {
@@ -46,6 +55,7 @@ type XMLParams struct {
ReportFile string `xml:"reportFile"` ReportFile string `xml:"reportFile"`
DataID string `xml:"dataId"` DataID string `xml:"dataId"`
DoPansharpen bool `xml:"doPansharpen"` DoPansharpen bool `xml:"doPansharpen"`
Targets ROITargets `xml:"targets"`
} }
func ParseXMLImageTask(xmlFile string) (*XMLImageTask, error) { func ParseXMLImageTask(xmlFile string) (*XMLImageTask, error) {

View File

@@ -29,6 +29,7 @@ type Scene struct {
Tiff string Tiff string
Meta *ProductMeta Meta *ProductMeta
SceneId string SceneId string
SceneIndex string
} }
func (s *Scene) Cleanup() { func (s *Scene) Cleanup() {
@@ -48,6 +49,10 @@ func CleanScenes(scenes []*Scene) {
// MSS 2336 * 2336 - 1764 // MSS 2336 * 2336 - 1764
// PAN 9344 * 9344 - 7056 // PAN 9344 * 9344 - 7056
func (r *Registrator) SubScenes() (panScenes []*Scene, mssScenes []*Scene, err error) { func (r *Registrator) SubScenes() (panScenes []*Scene, mssScenes []*Scene, err error) {
if len(r.Params.Targets.Targets) > 0 && r.Params.Targets.Targets[0].EndLine > 0 {
return r.RoiScenes()
}
hPAN := (payload.PAN_PIXEL_WIDTH - payload.MSS_PIXEL_WIDTH) hPAN := (payload.PAN_PIXEL_WIDTH - payload.MSS_PIXEL_WIDTH)
hPANOverlap := payload.MSS_PIXEL_WIDTH hPANOverlap := payload.MSS_PIXEL_WIDTH
panScenesCnt := r.PanHeight / hPAN panScenesCnt := r.PanHeight / hPAN
@@ -64,6 +69,7 @@ func (r *Registrator) SubScenes() (panScenes []*Scene, mssScenes []*Scene, err e
Height: y1 - i*hPAN, Height: y1 - i*hPAN,
X: 0, X: 0,
Y: i * hPAN, Y: i * hPAN,
SceneIndex: fmt.Sprintf("%03d", i+1),
} }
if scene.Height < scene.Width/2 { if scene.Height < scene.Width/2 {
@@ -106,6 +112,7 @@ func (r *Registrator) SubScenes() (panScenes []*Scene, mssScenes []*Scene, err e
Height: y1 - i*hMSS, Height: y1 - i*hMSS,
X: 0, X: 0,
Y: i * hMSS, Y: i * hMSS,
SceneIndex: fmt.Sprintf("%03d", i+1),
} }
if scene.Height < scene.Width/2 { if scene.Height < scene.Width/2 {
@@ -147,7 +154,7 @@ func (r *Registrator) SubScenes() (panScenes []*Scene, mssScenes []*Scene, err e
func (r *Registrator) SaveScenesToTiff(panScenes []*Scene, mssScenes []*Scene) error { func (r *Registrator) SaveScenesToTiff(panScenes []*Scene, mssScenes []*Scene) error {
var fc geojson.FeatureCollection var fc geojson.FeatureCollection
for i, scene := range panScenes { for i, scene := range panScenes {
dir := filepath.Join(r.Params.OutputDir, fmt.Sprintf("%03d", i+1), "PAN") dir := filepath.Join(r.Params.OutputDir, scene.SceneIndex, "PAN")
os.MkdirAll(dir, 0755) os.MkdirAll(dir, 0755)
filename := fmt.Sprintf("%s_L1A.tiff", scene.SceneId) filename := fmt.Sprintf("%s_L1A.tiff", scene.SceneId)
@@ -194,7 +201,7 @@ func (r *Registrator) SaveScenesToTiff(panScenes []*Scene, mssScenes []*Scene) e
log.Debug(string(data)) log.Debug(string(data))
for i, scene := range mssScenes { for i, scene := range mssScenes {
dir := filepath.Join(r.Params.OutputDir, fmt.Sprintf("%03d", i+1), "MSS") dir := filepath.Join(r.Params.OutputDir, scene.SceneIndex, "MSS")
os.MkdirAll(dir, 0755) os.MkdirAll(dir, 0755)
filename := fmt.Sprintf("%s_L1A.tiff", scene.SceneId) filename := fmt.Sprintf("%s_L1A.tiff", scene.SceneId)
@@ -264,3 +271,97 @@ func (r *Registrator) MergeMSSToBGRNIR(channels []gocv.Mat) (gocv.Mat, error) {
return rgbirImage, nil return rgbirImage, nil
} }
func (r *Registrator) RoiScenes() (panScenes []*Scene, mssScenes []*Scene, err error) {
log.Println("using target scenes")
for _, target := range r.Params.Targets.Targets {
y0 := 4 * target.StartLine
y1 := 4 * target.EndLine
if y1 > r.PanHeight {
y1 = r.PanHeight
}
scene := &Scene{
Type: "PAN",
Width: payload.PAN_PIXEL_WIDTH,
Height: y1 - y0,
X: 0,
Y: y0,
SceneIndex: fmt.Sprintf("ROI_%d_%d", target.StartLine, target.EndLine),
}
if scene.Height < scene.Width/2 {
log.Info("scene height too small, skip")
continue
}
name := filepath.Base(r.Params.PanTiffFile)
name = strings.TrimSuffix(name, ".tiff")
scene.SceneId = fmt.Sprintf("%s_ROI_%d_%d", name, target.StartLine, target.EndLine)
mat := r.PanImage.Region(image.Rect(0, y0, 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)
mat.Close()
mat = matFiltered
}
if config.GCONFIG.Radiation.SceneMomentMatching {
rrc.DoMomentMatching(mat)
}
scene.Mat = append(scene.Mat, mat)
panScenes = append(panScenes, scene)
}
for _, target := range r.Params.Targets.Targets {
y0 := target.StartLine
y1 := target.EndLine
if y1 > r.MssHeight {
y1 = r.MssHeight
}
scene := &Scene{
Type: "MSS",
Width: payload.MSS_PIXEL_WIDTH,
Height: y1 - y0,
X: 0,
Y: y0,
SceneIndex: fmt.Sprintf("ROI_%d_%d", target.StartLine, target.EndLine),
}
if scene.Height < scene.Width/2 {
log.Info("scene height too small, skip")
continue
}
name := filepath.Base(r.Params.MssTiffFile)
name = strings.TrimSuffix(name, ".tiff")
scene.SceneId = fmt.Sprintf("%s_ROI_%d_%d", name, target.StartLine, target.EndLine)
for band := 0; band < 4; band++ {
mat := r.registeredMssImages[band].Region(image.Rect(0, y0, 2336, y1))
if config.GCONFIG.Radiation.MSSRemoveHfNoise {
log.Println("applying hf noise filter on", scene.SceneId)
matFiltered := rrc.HFNoiseFilter(mat, float64(mat.Cols())*config.GCONFIG.Radiation.HfRadiusRatio/4)
mat.Close()
mat = matFiltered
}
if config.GCONFIG.Radiation.SceneMomentMatching {
rrc.DoMomentMatching(mat)
}
scene.Mat = append(scene.Mat, mat)
}
mssScenes = append(mssScenes, scene)
}
if len(panScenes) != len(mssScenes) {
log.Error("pan and mss scenes count not match")
err = fmt.Errorf("pan and mss scenes count not match")
}
return panScenes, mssScenes, err
}