cloud cover by kmeans
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"gocv.io/x/gocv"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -36,6 +37,20 @@ func CloudPercentByKMeans(imagePath string) float64 {
|
|||||||
return 0.0
|
return 0.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return computeCloudCoverByKMeans(img)
|
||||||
|
}
|
||||||
|
|
||||||
|
func CloudPercentByKMeans2(imgMat gocv.Mat) float64 {
|
||||||
|
img, err := imgMat.ToImage()
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("无法将Mat转换为Image: %v", err)
|
||||||
|
return 0.0
|
||||||
|
}
|
||||||
|
return computeCloudCoverByKMeans(img)
|
||||||
|
}
|
||||||
|
|
||||||
|
func computeCloudCoverByKMeans(img image.Image) float64 {
|
||||||
|
log.Info("cloud cover computing...")
|
||||||
bounds := img.Bounds()
|
bounds := img.Bounds()
|
||||||
width, height := bounds.Max.X, bounds.Max.Y
|
width, height := bounds.Max.X, bounds.Max.Y
|
||||||
pixels := make([]Pixel, 0, width*height)
|
pixels := make([]Pixel, 0, width*height)
|
||||||
@@ -62,7 +77,7 @@ func CloudPercentByKMeans(imagePath string) float64 {
|
|||||||
|
|
||||||
newCentroids := updateCentroids(pixels, assignments)
|
newCentroids := updateCentroids(pixels, assignments)
|
||||||
if hasConverged(centroids, newCentroids) {
|
if hasConverged(centroids, newCentroids) {
|
||||||
log.Printf("在第 %d 次迭代后收敛\n", iter+1)
|
log.Debugf("Convergence after the %d iteration", iter+1)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
centroids = newCentroids
|
centroids = newCentroids
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/paulmach/orb/geojson"
|
"github.com/paulmach/orb/geojson"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"gocv.io/x/gocv"
|
"gocv.io/x/gocv"
|
||||||
|
cloudcover "starwiz.cn/sjy01/image-proc/pkg/cloud-cover"
|
||||||
"starwiz.cn/sjy01/image-proc/pkg/config"
|
"starwiz.cn/sjy01/image-proc/pkg/config"
|
||||||
"starwiz.cn/sjy01/image-proc/pkg/fusion"
|
"starwiz.cn/sjy01/image-proc/pkg/fusion"
|
||||||
"starwiz.cn/sjy01/image-proc/pkg/payload"
|
"starwiz.cn/sjy01/image-proc/pkg/payload"
|
||||||
@@ -231,11 +232,13 @@ func (r *ImgProc) OutputL1A(panScenes []*Scene, mssScenes []*Scene) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jpg := strings.Replace(scene.Tiff, ".tiff", ".jpg", 1)
|
||||||
|
GTiffToJPG(scene.Tiff, jpg, "MSS", false)
|
||||||
|
scene.Meta.CloudRate = cloudcover.CloudPercentByKMeans(jpg)
|
||||||
scene.Meta.DataSize = sizeOfFile(scene.Tiff)
|
scene.Meta.DataSize = sizeOfFile(scene.Tiff)
|
||||||
metaFile := strings.Replace(scene.Tiff, ".tiff", ".meta.xml", 1)
|
metaFile := strings.Replace(scene.Tiff, ".tiff", ".meta.xml", 1)
|
||||||
writeProductMeta(scene.Meta, metaFile)
|
writeProductMeta(scene.Meta, metaFile)
|
||||||
jpg := strings.Replace(scene.Tiff, ".tiff", ".jpg", 1)
|
|
||||||
GTiffToJPG(scene.Tiff, jpg, "MSS", false)
|
|
||||||
r.report.Scenes = append(r.report.Scenes, ReportScene{
|
r.report.Scenes = append(r.report.Scenes, ReportScene{
|
||||||
Name: scene.SceneId,
|
Name: scene.SceneId,
|
||||||
TiffData: scene.Tiff,
|
TiffData: scene.Tiff,
|
||||||
|
|||||||
Reference in New Issue
Block a user