Files
kenaito-media-picker/internal/classify/brightness.go
T
odboy 8979c744a8 refactor: 全面重构代码并加白话注释,移动全局并行,去掉去向/重复记录
- 重构后端与前端,全程大白话注释(不懂程序也能看懂)
- 移动阶段改为全局并行(MoveAll,工人数=CPU核心数)
- 去掉记录每个文件搬去哪了(删除去向回填,解决写库卡顿)
- 去掉重复文件标记与统计:重复判定改为 MD5+路径都相同才算,重复则原地忽略不移动;MD5 相同但路径不同仍照常搬
- 媒体库去掉归类目录列,看板去掉重复/归类分布统计
2025-05-11 21:05:35 +08:00

40 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package classify
import "fmt"
// neutralMargin 判定"中性图"的最小分差:
// 如果亮色占比和暗色占比相差不到这个值,就认为这张图不亮不暗,归为「mid」中性。
const neutralMargin = 0.15
// BrightnessName 根据暗色/亮色像素占比,给图片定"明暗等级",返回类似:
// - "dark_70" → 暗色像素占 65%~75% 的暗图
// - "bright_40" → 亮色像素占 35%~45% 的亮图
// - "mid" → 明暗差不多,不好说谁多,归中性
//
// 判断规则(大白话):谁占得多、而且多出明显一截(超过 neutralMargin),
// 就按谁命名,数字是占比取整到 10% 一档。
func BrightnessName(darkScore, lightScore float64) string {
switch {
case lightScore > darkScore+neutralMargin:
return fmt.Sprintf("bright_%d", brightnessTier(lightScore))
case darkScore > lightScore+neutralMargin:
return fmt.Sprintf("dark_%d", brightnessTier(darkScore))
default:
return "mid"
}
}
// brightnessTier 把占比(0~1)取整到"最接近的 10%"作为档位数字,范围 10~100。
// 例:0.30~0.39 → "30";0.96 以上 → "100"。
// 这样文件夹名里的数字不会出现"明明很少却挂个大数字"的情况。
func brightnessTier(score float64) int {
tier := int(score*100+5) / 10 * 10
if tier < 10 {
return 10
}
if tier > 100 {
return 100
}
return tier
}