From 0d1fea2f5d35e512b8ef84d46272b3dc644c9a46 Mon Sep 17 00:00:00 2001 From: nuknal Date: Thu, 18 Jul 2024 10:24:07 +0800 Subject: [PATCH] different enhancement method for different sensor type --- cmd/fus.go | 2 +- pkg/config/config.go | 12 ++++++++---- pkg/producer/image_proc_test.go | 6 +++--- pkg/producer/jpg.go | 8 ++++++-- pkg/producer/scenes.go | 6 +++--- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/cmd/fus.go b/cmd/fus.go index 0bcc5ec..b1a6812 100644 --- a/cmd/fus.go +++ b/cmd/fus.go @@ -36,7 +36,7 @@ var fusCmd = &cobra.Command{ } godal.RegisterAll() - producer.GTiffToJPG(filepath.Join(outputDir, fusedTiff), filepath.Join(outputDir, id+".jpg"), true) + producer.GTiffToJPG(filepath.Join(outputDir, fusedTiff), filepath.Join(outputDir, id+".jpg"), "FUS", true) var report producer.Report report.Satellite = "SJY01" diff --git a/pkg/config/config.go b/pkg/config/config.go index cfb9a9a..f651a22 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -35,9 +35,9 @@ type RadiationConfig struct { } type BrowserImgConfig struct { - Enhancement string `yaml:"enhancement" mapstructure:"enhancement"` - CumulativeCutLower float64 `yaml:"cumulative_cut_lower" mapstructure:"cumulative_cut_lower"` - CumulativeCutUpper float64 `yaml:"cumulative_cut_upper" mapstructure:"cumulative_cut_upper"` + Enhancement map[string]string `yaml:"enhancement" mapstructure:"enhancement"` + CumulativeCutLower float64 `yaml:"cumulative_cut_lower" mapstructure:"cumulative_cut_lower"` + CumulativeCutUpper float64 `yaml:"cumulative_cut_upper" mapstructure:"cumulative_cut_upper"` } var GCONFIG Config @@ -66,7 +66,11 @@ func init() { HFBandStopWidth: 24, }, BrowserImg: BrowserImgConfig{ - Enhancement: "StretchToCumulativeCutMinMax", + Enhancement: map[string]string{ + "MSS": "StretchToCumulativeCutMinMax", + "PAN": "StretchToMinimumMaximum", + "FUS": "StretchToCumulativeCutMinMax", + }, CumulativeCutLower: 0.01, CumulativeCutUpper: 0.99, }, diff --git a/pkg/producer/image_proc_test.go b/pkg/producer/image_proc_test.go index e34fc21..f266901 100644 --- a/pkg/producer/image_proc_test.go +++ b/pkg/producer/image_proc_test.go @@ -20,21 +20,21 @@ func TestGTiffToJPG(t *testing.T) { godal.RegisterAll() tiff := "../data/051622/006/MSS/SJY01_MSS_20240516_101236_051622_096_006.tiff" jpg := "../data/051622/006/MSS/SJY01_MSS_20240516_101236_051622_096_006.jpg" - err := GTiffToJPG(tiff, jpg, false) + err := GTiffToJPG(tiff, jpg, "MSS", false) if err != nil { t.Error(err) } tiff = "../data/051622/006/PAN/SJY01_PAN_20240516_101236_051622_096_006.tiff" jpg = "../data/051622/006/PAN/SJY01_PAN_20240516_101236_051622_096_006.jpg" - err = GTiffToJPG(tiff, jpg, false) + err = GTiffToJPG(tiff, jpg, "PAN", false) if err != nil { t.Error(err) } tiff = "../data/051622/006/FUS/SJY01_FUS_20240516_101236_051622_096_006.tiff" jpg = "../data/051622/006/FUS/SJY01_FUS_20240516_101236_051622_096_006.jpg" - err = GTiffToJPG(tiff, jpg, true) + err = GTiffToJPG(tiff, jpg, "FUS", true) if err != nil { t.Error(err) } diff --git a/pkg/producer/jpg.go b/pkg/producer/jpg.go index ebcf460..853858e 100644 --- a/pkg/producer/jpg.go +++ b/pkg/producer/jpg.go @@ -11,7 +11,7 @@ import ( "starwiz.cn/sjy01/image-proc/pkg/config" ) -func GTiffToJPG(ftiff, fjpg string, reversed bool) error { +func GTiffToJPG(ftiff, fjpg, sensor string, reversed bool) error { // 打开 TIFF 文件 ds, err := godal.Open(ftiff) if err != nil { @@ -58,8 +58,12 @@ func GTiffToJPG(ftiff, fjpg string, reversed bool) error { } channels := gocv.Split(img) + enhancement, ok := config.GCONFIG.BrowserImg.Enhancement[sensor] + if !ok { + enhancement = "NoEnhancement" + } for i, ch := range channels { - switch config.GCONFIG.BrowserImg.Enhancement { + switch enhancement { case StretchToCumulativeCutMinMax: channels[i] = cumulativeCountCutEnhancement(ch, config.GCONFIG.BrowserImg.CumulativeCutLower, diff --git a/pkg/producer/scenes.go b/pkg/producer/scenes.go index 3a1d9a9..4006a10 100644 --- a/pkg/producer/scenes.go +++ b/pkg/producer/scenes.go @@ -169,7 +169,7 @@ func (r *Registrator) SaveScenesToTiff(panScenes []*Scene, mssScenes []*Scene) e metaFile := strings.Replace(scene.Tiff, ".tiff", ".meta.xml", 1) r.writeProductMeta(scene.Meta, metaFile) jpg := strings.Replace(scene.Tiff, ".tiff", ".jpg", 1) - GTiffToJPG(scene.Tiff, jpg, false) + GTiffToJPG(scene.Tiff, jpg, "PAN", false) r.report.Scenes = append(r.report.Scenes, ReportScene{ Name: scene.SceneId, TiffData: scene.Tiff, @@ -219,7 +219,7 @@ func (r *Registrator) SaveScenesToTiff(panScenes []*Scene, mssScenes []*Scene) e metaFile := strings.Replace(scene.Tiff, ".tiff", ".meta.xml", 1) r.writeProductMeta(scene.Meta, metaFile) jpg := strings.Replace(scene.Tiff, ".tiff", ".jpg", 1) - GTiffToJPG(scene.Tiff, jpg, false) + GTiffToJPG(scene.Tiff, jpg, "MSS", false) r.report.Scenes = append(r.report.Scenes, ReportScene{ Name: scene.SceneId, TiffData: scene.Tiff, @@ -240,7 +240,7 @@ func (r *Registrator) DoScenePansharpen(panScenes []*Scene, mssScenes []*Scene) } jpg := strings.Replace(fusedTiff, ".tiff", ".jpg", 1) - GTiffToJPG(fusedTiff, jpg, true) + GTiffToJPG(fusedTiff, jpg, "FUS", true) r.report.Scenes = append(r.report.Scenes, ReportScene{ TiffData: fusedTiff, Name: strings.TrimSuffix(filepath.Base(fusedTiff), ".tiff"),