Skip to main content

Cleaning up documents with the Windows Document Scanner

Document Cleanup lets the end user erase unwanted artifacts from a scanned page while preserving the underlying document content. Artifacts include handwriting, stamps, stains, fingers, shadows, and other distracting elements. The user paints over the regions to remove. The SDK then reconstructs a clean result image, with optional text preservation.

Cleaning up an image​

The examples below load a source image and a matching mask image, create a DocumentCleanup pipeline, run one cleanup pass, and optionally save the result to disk.

cleaning up a document
loading...

Configuration options​

Configure the cleanup behavior of the underlying engine through DocumentCleanupConfiguration. In the Ready-to-Use UI, pass it as screens.cleanup.engineConfiguration.

PropertyTypeDefaultDescription
keepTextBooleantrueIf true, the SDK keeps detected text intact while the user erases around it. Text detection runs once up front and can take a moment, so construct the cleanup pipeline asynchronously to keep the UI responsive.
maxUndoRedoStackSizeInt10How many undo and redo steps the SDK keeps in memory. Use at least 1 so that reset can always restore the original image. When the limit is reached, the SDK merges the two oldest steps into one. The user can still return to the original image, but with fewer steps in between.
maxCleanupResolutionInt0Caps the brushed area the SDK processes in one cleanup step, as width × height in pixels. Larger areas are processed at a lower resolution and scaled back up, which saves memory but can soften the edges near the stroke. 0 means no limit. For example, 1200000 keeps peak memory at about 0.5 GB for a 12 MP image. Prefer cleaning smaller areas over relying on this limit.

Cleanup status​

A cleanup run reports a DocumentCleanupStatus alongside the resulting image:

ValueMeaning
OKCleanup completed at full resolution.
OK_BUT_REDUCED_QUALITYCleanup completed, but maxCleanupResolution forced an internal downscale of the cleanup region, so quality near the cleanup boundary may be reduced. If the result is not good enough, undo the last operation and apply cleanup on a smaller area.

Undo, redo, reset​

DocumentCleanup is stateful across run(mask) calls. Each successful cleanup pushes a new entry onto an internal undo stack (limited by maxUndoRedoStackSize):

  • Undo reverts the last cleanup and returns the previous image. If no operation is available, the current image is returned unchanged.
  • Redo re-applies the last undone cleanup. Performing a new cleanup after an undo clears the redo history.
  • Reset restores the original input image and clears the undo/redo history. After reset, both canUndo and canRedo return false.
MethodDescription
cleanup.undo()Revert the last cleanup. Returns the current image.
cleanup.redo()Re-apply the last undone cleanup. Returns the current image.
cleanup.reset()Restore the original image and clear the history.
cleanup.can_undoTrue if an undo operation is available.
cleanup.can_redoTrue if a redo operation is available.

Want to scan longer than one minute?

Generate a free trial license to test the Scanbot SDK thoroughly.

Get free trial license