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.ReportFile = task.Params.ReportFile
taskParams.DataId = task.Params.DataID
taskParams.Targets = task.Params.Targets
}
taskParams.MssTiffFile = filepath.Join(taskParams.OutputDir, strings.TrimSuffix(filepath.Base(taskParams.MssRawFile),

View File

@@ -18,6 +18,15 @@ type Params struct {
SubScenes bool
ReportFile 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 {
@@ -36,16 +45,17 @@ type XMLInputFileList struct {
}
type XMLParams struct {
Satellite string `xml:"satellite"`
Sensor string `xml:"sensor"`
ProductLevel string `xml:"productLevel"`
ProductID string `xml:"productId"`
TempPath string `xml:"tempPath"`
OutputPath string `xml:"outputPath"`
DeleteTempFlag int `xml:"deleteTempFlag"`
ReportFile string `xml:"reportFile"`
DataID string `xml:"dataId"`
DoPansharpen bool `xml:"doPansharpen"`
Satellite string `xml:"satellite"`
Sensor string `xml:"sensor"`
ProductLevel string `xml:"productLevel"`
ProductID string `xml:"productId"`
TempPath string `xml:"tempPath"`
OutputPath string `xml:"outputPath"`
DeleteTempFlag int `xml:"deleteTempFlag"`
ReportFile string `xml:"reportFile"`
DataID string `xml:"dataId"`
DoPansharpen bool `xml:"doPansharpen"`
Targets ROITargets `xml:"targets"`
}
func ParseXMLImageTask(xmlFile string) (*XMLImageTask, error) {

View File

@@ -20,15 +20,16 @@ import (
)
type Scene struct {
Type string
Width int
Height int
X int // coordinate of the left top corner of the scene
Y int
Mat []gocv.Mat
Tiff string
Meta *ProductMeta
SceneId string
Type string
Width int
Height int
X int // coordinate of the left top corner of the scene
Y int
Mat []gocv.Mat
Tiff string
Meta *ProductMeta
SceneId string
SceneIndex string
}
func (s *Scene) Cleanup() {
@@ -48,6 +49,10 @@ func CleanScenes(scenes []*Scene) {
// MSS 2336 * 2336 - 1764
// PAN 9344 * 9344 - 7056
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)
hPANOverlap := payload.MSS_PIXEL_WIDTH
panScenesCnt := r.PanHeight / hPAN
@@ -59,11 +64,12 @@ func (r *Registrator) SubScenes() (panScenes []*Scene, mssScenes []*Scene, err e
}
scene := &Scene{
Type: "PAN",
Width: payload.PAN_PIXEL_WIDTH,
Height: y1 - i*hPAN,
X: 0,
Y: i * hPAN,
Type: "PAN",
Width: payload.PAN_PIXEL_WIDTH,
Height: y1 - i*hPAN,
X: 0,
Y: i * hPAN,
SceneIndex: fmt.Sprintf("%03d", i+1),
}
if scene.Height < scene.Width/2 {
@@ -101,11 +107,12 @@ func (r *Registrator) SubScenes() (panScenes []*Scene, mssScenes []*Scene, err e
}
scene := &Scene{
Type: "MSS",
Width: payload.MSS_PIXEL_WIDTH,
Height: y1 - i*hMSS,
X: 0,
Y: i * hMSS,
Type: "MSS",
Width: payload.MSS_PIXEL_WIDTH,
Height: y1 - i*hMSS,
X: 0,
Y: i * hMSS,
SceneIndex: fmt.Sprintf("%03d", i+1),
}
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 {
var fc geojson.FeatureCollection
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)
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))
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)
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
}
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
}