How to Correct Images Using Filters for Reading

This article was translated from English: Does it need improvement?
Translated
View the article in English

圖像校正濾鏡是數字圖像處理技術,用於改善圖像的質量和特性,特別是為了增強文字識別和提取的效果。 IronOcr 中可用的圖像校正濾鏡包括銳化、增強解析度、去噪、膨脹和侵蝕。

這些圖像校正濾鏡在 OCR 前的圖像預處理中起著關鍵作用,因為它們通過改進文本的質量和可見性並減少不需要的噪聲或人工痕跡,幫助優化圖像以進行準確的文本提取。

快速入門:應用銳化濾鏡以獲得清晰文字

使用 IronOCR 的 OcrImageInput 用單行代碼銳化模糊圖像。 這個快速入門展示了如何用最少的努力最快速地增強圖像清晰度以準備進行準確的 OCR。

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronOCR with NuGet Package Manager

    PM > Install-Package IronOcr

  2. Copy and run this code snippet.

    new IronOcr.OcrImageInput("sample.png").Sharpen().SaveAsImages("output.png");
  3. Deploy to test on your live environment

    Start using IronOCR in your project today with a free trial
    arrow pointer
class="hsg-featured-snippet">

最小化工作流程(5 步驟)

  1. 下載用於圖像校正的 C# 庫
  2. 導入 PDF 文檔和圖像以進行閱讀
  3. 應用所需的濾鏡,例如銳化、增強解析度、去噪、膨脹和侵蝕
  4. 導出校正過的圖像以供查看
  5. 利用 Read 方法進行 OCR 處理


銳化濾鏡範例

這個濾鏡增加圖像的邊緣對比度,給予它們更鮮明的外觀。 它提高了文本和細節的清晰度,使 OCR 軟件更容易識別字符。

要應用銳化濾鏡,調用 OcrImageInput 對象的 Sharpen 方法。

:path=/static-assets/ocr/content-code-examples/how-to/image-quality-correction-sharpen-filter.cs
using IronOcr;

// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();

// Add image
using var imageInput = new OcrImageInput("sample.jpg");
// Apply sharpen filter
imageInput.Sharpen();

// Export filtered image
imageInput.SaveAsImages("sharpen.jpg");
Imports IronOcr

' Instantiate IronTesseract
Private ocrTesseract As New IronTesseract()

' Add image
Private imageInput = New OcrImageInput("sample.jpg")
' Apply sharpen filter
imageInput.Sharpen()

' Export filtered image
imageInput.SaveAsImages("sharpen.jpg")
$vbLabelText   $csharpLabel

為方便起見,可以使用 SaveAsImages 方法導出過濾的圖像。 以下是應用銳化濾鏡前後圖像的對比。

class="competitors-section__wrapper-even-1">
Sample image
Sharpen filter applied

增強解析度濾鏡範例

此濾鏡旨在增加圖像的像素密度,有效提高其清晰度和清晰度。 它對提高低解析度圖像中文本的可讀性特別有用。

調用 EnhanceResolution 方法應用增強解析度濾鏡。 此方法接受目標 DPI,預設值為 225 DPI。

:path=/static-assets/ocr/content-code-examples/how-to/image-quality-correction-enhance-resolution-filter.cs
// Apply enhance resolution filter
imageInput.EnhanceResolution();
' Apply enhance resolution filter
imageInput.EnhanceResolution()
$vbLabelText   $csharpLabel
class="competitors-section__wrapper-even-1">
Sample image
Enhance resolution filter applied

去噪濾鏡範例

去噪濾鏡可降低圖像中的噪聲或不需要的人工痕跡。 噪聲的減少對於 OCR 至關重要,因為它有助於隔離文本與背景干擾,從而獲得更清晰和更準確的識別。

要應用去噪濾鏡,使用 DeNoise 方法。 預設形態為 2x2。要應用更強的去噪算法,傳遞 'true' 以啟用 3x3 形態。

:path=/static-assets/ocr/content-code-examples/how-to/image-quality-correction-denoise-filter.cs
// Apply denoise filter
imageInput.DeNoise();
' Apply denoise filter
imageInput.DeNoise()
$vbLabelText   $csharpLabel
class="competitors-section__wrapper-even-1">
Sample image
Denoise filter applied

膨脹濾鏡範例

膨脹擴大圖像中的亮區(前景)。 它有助於加粗並增強文本,使其更突出,更易於 OCR 軟件解釋。

要應用膨脹濾鏡,使用 Dilate 方法。 預設形態為 2x2,設置 'true' 能夠啟用 3x3 選項。

:path=/static-assets/ocr/content-code-examples/how-to/image-quality-correction-dilate-filter.cs
// Apply dilate filter
imageInput.Dilate();
' Apply dilate filter
imageInput.Dilate()
$vbLabelText   $csharpLabel
class="competitors-section__wrapper-even-1">
Sample image
Dilate filter applied

侵蝕濾鏡範例

侵蝕減少圖像中亮區的大小,特別有助於細化字符和線條,尤其是在它們過厚或扭曲時。

使用 Erode 方法來應用侵蝕濾鏡。 與先前的方法一樣,預設形態為 2x2,設置 'true' 可以啟用 3x3。

:path=/static-assets/ocr/content-code-examples/how-to/image-quality-correction-erode-filter.cs
// Apply erode filter
imageInput.Erode();
' Apply erode filter
imageInput.Erode()
$vbLabelText   $csharpLabel
class="competitors-section__wrapper-even-1">
Sample image
Erode filter applied

可搜索的 PDF

除了濾鏡圖像的選項,IronOcr 還為開發人員提供了靈活性,可以選擇將修改後的 PDF 保存為應用濾鏡或不應用濾鏡。 SaveAsSearchablePdf 方法允許將布爾標誌作為第二個參數,以確定是否希望應用濾鏡保存。

:path=/static-assets/ocr/content-code-examples/how-to/image-quality-correction-searchable-pdf.cs
using IronOcr;

var ocr = new IronTesseract();
var ocrInput = new OcrInput();

// Load a PDF file
ocrInput.LoadPdf("invoice.pdf");

// Apply gray scale filter
ocrInput.ToGrayScale();
OcrResult result = ocr.Read(ocrInput);

// Save the result as a searchable PDF with filters applied
result.SaveAsSearchablePdf("outputGrayscale.pdf", true);
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

常見問題解答

如何提高影像品質以獲得更好的OCR辨識結果?

您可以使用 IronOCR 透過應用各種影像校正濾鏡(例如銳利化、提高解析度、降噪、膨脹和腐蝕)來提升影像質量,從而獲得更好的 OCR 識別結果。這些濾鏡可以提高文字清晰度並降低噪聲,有助於更準確地提取文字。

在影像預處理中使用銳利化濾波器有哪些好處?

IronOCR中的銳利化濾鏡可增強邊緣對比度,從而提高影像中文字的清晰度和可讀性。這種增強對於提高OCR文字辨識的準確率至關重要。

如何提高影像解析度以進行OCR處理?

若要提高 IronOCR 中 OCR 處理的影像分辨率,請使用增強解析度濾鏡,可提高像素密度,從而提高低解析度影像的清晰度和銳利度。

在進行OCR辨識之前,我應該採取哪些步驟來降低影像雜訊?

在使用 IronOCR 進行 OCR 之前,為了降低影像雜訊,請應用「DeNoise」方法。為了獲得更強的降噪效果,您可以透過將選項設為「true」來啟用 3x3 形態學。

膨脹濾波如何影響影像中的文字可見性?

IronOCR 中的膨脹濾波會擴大影像中較亮的區域,使文字更加突出,從而幫助 OCR 過程更有效地解釋字元。

如何使用腐蝕濾波器來優化文字?

要在 IronOCR 中使用腐蝕濾鏡來優化文本,請使用「腐蝕」方法。此濾鏡會縮小影像中明亮區域的大小,從而幫助優化影像中較粗或扭曲的字元和線條。

為了提高影像分辨率,建議使用什麼DPI設定?

IronOCR中增強解析度濾鏡的預設DPI設定為225 DPI。但是,您可以根據需要指定不同的DPI以優化影像清晰度。

IronOCR 中是否可以調節擴張效應的強度?

是的,您可以透過在應用膨脹濾鏡期間啟用更強的 3x3 形態來調整 IronOCR 中的膨脹效果強度,這可以透過將選項設為「true」來實現。

如何在.NET C#中使用影像校正濾鏡?

若要開始在 .NET C# 中使用影像校正濾鏡,請透過 NuGet 下載 IronOCR 庫,匯入影像,套用所需的濾鏡(如銳利化或降噪),然後匯出增強後的影像以進行 OCR 處理。

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'name'

Filename: sections/author_component.php

Line Number: 18

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 18
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'title'

Filename: sections/author_component.php

Line Number: 38

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 38
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'comment'

Filename: sections/author_component.php

Line Number: 48

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 48
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

準備好開始了嗎?
Nuget 下載 5,044,537 | 版本: 2025.11 剛剛發布