修复阴影区域文字被模糊:改用墨迹强度判断代替方差

阴影区域内文字的局部方差被暗背景拉低导致误判。
改为直接看墨迹强度(inkData):>40说明有明显文字笔画保留,
<40说明是阴影背景推白。墨迹强度不受背景亮度影响。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-19 17:11:43 +08:00
parent 3f30a9e79d
commit ed205c4f04

View File

@@ -576,18 +576,20 @@ public static class DocumentScanner
Marshal.Copy(shadowMask.Data, shadowMaskData, 0, shadowMaskData.Length); Marshal.Copy(shadowMask.Data, shadowMaskData, 0, shadowMaskData.Length);
shadowMask.Dispose(); shadowMask.Dispose();
// 在阴影区域内:高方差像素保留(文字),低方差推白 // 在阴影区域内:保护文字,只清除阴影背景
// 判断逻辑:
// 墨迹强度高inkData > 40→ 有明显文字 → 保留
// 墨迹强度低 → 阴影背景 → 推白
for (int i = 0; i < resultData.Length; i++) for (int i = 0; i < resultData.Length; i++)
{ {
if (shadowMaskData[i] > 128) if (shadowMaskData[i] > 128)
{ {
// 在大面积暗区域内 if (inkData[i] < 40)
if (varDataS[i] < 12)
{ {
// 低方差 → 阴影本身 → 白色 // 墨迹弱 → 阴影背景 → 白色
resultData[i] = 255; resultData[i] = 255;
} }
// 高方差 → 文字 → 保留 // 墨迹强 → 文字 → 保留原值
} }
} }