增加云判阈值条件

This commit is contained in:
nuknal
2024-11-13 17:49:19 +08:00
parent 98f12606b6
commit 1e738907c7

View File

@@ -14,9 +14,10 @@ import (
)
const (
k = 2 // 聚类数目2表示云和非云
maxIters = 100 // 最大迭代次数
tolerance = 1.0 // 聚类中心变化容忍度
k = 2 // 聚类数目2表示云和非云
maxIters = 100 // 最大迭代次数
tolerance = 1.0 // 聚类中心变化容忍度
brightnessThreshold = 220 // 亮度阈值,值越大要求云更亮
)
type Pixel struct {
@@ -96,7 +97,15 @@ func computeCloudCoverByKMeans(img image.Image) float64 {
for y := 0; y < height; y++ {
for x := 0; x < width; x++ {
i := y*width + x
if assignments[i] == cloudCluster {
pixel := pixels[i]
// 计算亮度和颜色比值
brightness := (pixel.r + pixel.g + pixel.b) / 3
blueRedRatio := pixel.b / pixel.r
greenRedRatio := pixel.g / pixel.r
// 判断是否为云的条件:亮度大于阈值并且蓝色/红色比率较高
if (assignments[i] == cloudCluster && brightness > brightnessThreshold && blueRedRatio > 0.5) ||
(assignments[i] == cloudCluster && greenRedRatio > 0.8) {
outputImg.SetGray(x, y, color.Gray{Y: 255}) // 云区域
cloudPixels++
} else {