增加云判阈值条件
This commit is contained in:
@@ -14,9 +14,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
k = 2 // 聚类数目,2表示云和非云
|
k = 2 // 聚类数目,2表示云和非云
|
||||||
maxIters = 100 // 最大迭代次数
|
maxIters = 100 // 最大迭代次数
|
||||||
tolerance = 1.0 // 聚类中心变化容忍度
|
tolerance = 1.0 // 聚类中心变化容忍度
|
||||||
|
brightnessThreshold = 220 // 亮度阈值,值越大要求云更亮
|
||||||
)
|
)
|
||||||
|
|
||||||
type Pixel struct {
|
type Pixel struct {
|
||||||
@@ -96,7 +97,15 @@ func computeCloudCoverByKMeans(img image.Image) float64 {
|
|||||||
for y := 0; y < height; y++ {
|
for y := 0; y < height; y++ {
|
||||||
for x := 0; x < width; x++ {
|
for x := 0; x < width; x++ {
|
||||||
i := y*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}) // 云区域
|
outputImg.SetGray(x, y, color.Gray{Y: 255}) // 云区域
|
||||||
cloudPixels++
|
cloudPixels++
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user