DeNoise()使彩色紙張的掃描效果變差
DeNoise() 會使彩色紙張的文檔變得更吵雜,而不是更乾淨,當它們被掃描為黑白時。頁面會變成均勻的灰色顆粒,而默認過濾器會誤將該顆粒讀作斑點。
DeNoise()(在內部別名為Despeckle())是為了一個工作而設計的:去除原本乾淨的白色背景上的小型、獨立的黑色斑點。 它無法適應連續的紋理。 當彩色紙張頁面被掃描為黑白時,它失去了顏色對比,變成整頁的均勻灰色調顆粒。 固定全域閾值將該顆粒讀作廣泛的斑點,而不是獨立的噪音,因此它放大了背景而不是移除它。 這是默認DeNoise()對此輸入類型的設計限制,而不是環境特定的錯誤。
解決方案
選項1:Adaptive DeNoise() (v2026.10.2+)
傳遞adaptive: true以將DeNoise()切換到本地(Sauvola)閾值,該設計適用於連續背景紋理的頁面,如彩色紙張掃描為黑白:
input.DeNoise(use3x3: false, adaptive: true);
普通DeNoise()保持其原始行為,因此這個模式需要顯式啟用。 在早期版本中,或者如果結果仍然吵雜,回退到AdaptiveThreshold()。
選項2:AdaptiveThreshold()
將DeNoise()替換為AdaptiveThreshold()以適應該文件類型:
using (var input = new OcrInput())
{
foreach (var imagePath in pageImagePaths)
{
input.LoadImage(imagePath);
}
// Replaces input.DeNoise() for this document type
input.AdaptiveThreshold(0.15f);
var ocrResult = ocr.Read(input);
ocrResult.SaveAsSearchablePdf(outputPath);
}Using input As New OcrInput()
For Each imagePath In pageImagePaths
input.LoadImage(imagePath)
Next
' Replaces input.DeNoise() for this document type
input.AdaptiveThreshold(0.15F)
Dim ocrResult = ocr.Read(input)
ocrResult.SaveAsSearchablePdf(outputPath)
End UsingUsing input As New OcrInput()
For Each imagePath In pageImagePaths
input.LoadImage(imagePath)
Next
' Replaces input.DeNoise() for this document type
input.AdaptiveThreshold(0.15F)
Dim ocrResult = ocr.Read(input)
ocrResult.SaveAsSearchablePdf(outputPath)
End UsingAdaptiveThreshold() 二值化對應於本地閾值,因此可以處理使固定閾值過濾器失效的整頁顆粒。 對thresholdLimit的良好調整範圍是0.10到0.20。
如果僅AdaptiveThreshold()不足以完全清理批次中的其他文件,請首先應用Contrast()以便在二值化之前擴大文本和背景之間的區分:
input.Contrast(1.3f); // try a range of 1.3f-1.4f
input.AdaptiveThreshold(0.15f);
DeNoise(),在管道中沒有Deskew或其他過濾器,已被確認對此輸入無效:它通過放大背景噪音來使圖像變得更差。Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。