cloud cover by kmeans
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gocv.io/x/gocv"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -36,6 +37,20 @@ func CloudPercentByKMeans(imagePath string) float64 {
|
||||
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()
|
||||
width, height := bounds.Max.X, bounds.Max.Y
|
||||
pixels := make([]Pixel, 0, width*height)
|
||||
@@ -62,7 +77,7 @@ func CloudPercentByKMeans(imagePath string) float64 {
|
||||
|
||||
newCentroids := updateCentroids(pixels, assignments)
|
||||
if hasConverged(centroids, newCentroids) {
|
||||
log.Printf("在第 %d 次迭代后收敛\n", iter+1)
|
||||
log.Debugf("Convergence after the %d iteration", iter+1)
|
||||
break
|
||||
}
|
||||
centroids = newCentroids
|
||||
|
||||
Reference in New Issue
Block a user