Table of Contents

Method DespeckleBitonal

Namespace
LMKit.Media.Image
Assembly
LM-Kit.NET.dll

DespeckleBitonal(DespeckleBitonalParameters)

Removes speckle noise (salt-and-pepper artifacts, scanner debris, photocopy specks) from a bitonal document image.

public int DespeckleBitonal(ImageBuffer.DespeckleBitonalParameters parameters = null)

Parameters

parameters ImageBuffer.DespeckleBitonalParameters

Optional parameters controlling speckle thresholds and neighborhood radius. When null, automatic DPI-based defaults are used.

Returns

int

The number of speckle components removed.

Remarks

This method implements a document-optimized, two-phase despeckle pipeline designed for pre-OCR cleanup of scanned or photographed documents:

  1. Connected component labeling with 8-connectivity identifies all discrete foreground regions and measures their pixel area using a run-length encoding approach for high throughput.
  2. Proximity-aware classification separates true speckle noise from diacritics and punctuation. Small components that are within a configurable distance of a text-sized component are preserved; isolated small components are erased.

The image must be in GRAY8 format with foreground pixels at 0 (black) and background at 255 (white). The operation is performed in place: speckle pixels are set to 255.

All threshold parameters scale automatically with image resolution when left at their default value of 0. Explicit overrides are available through ImageBuffer.DespeckleBitonalParameters.

Exceptions

InvalidOperationException

Thrown if the image format is not GRAY8 or BINARY1.

ObjectDisposedException

Thrown if this instance has been disposed.

Share