Background
AIToolYes
Back to Blog
Computer VisionEngineeringOpenCVAlgorithms

The Mathematics of Perfect Document Scanning

June 11, 2026AIToolYes Engineering

Beyond the "Canny" Edge Detector

Most basic document scanners use a simple Canny edge detector. While fine for perfect lighting, it completely fails if the document has shadows, wrinkles, or is placed on a textured table.

At AIToolYes.com, we completely rewrote the rulebook for document scanning in the browser.

Adaptive Lighting with CLAHE

If your document is half in the sun and half in the dark, a standard threshold will destroy the image. We use Contrast Limited Adaptive Histogram Equalization (CLAHE). This algorithm divides the image into microscopic 8x8 grids, equalizing the lighting locally. The result? Perfect edge visibility in any environment.

The Morphological Engine

Instead of just finding edges, we use a Morphological Gradient (the mathematical difference between Dilation and Erosion). This allows the AI to ignore internal text and focus exclusively on the physical border of the paper.

Predictive Convex Hulls

What if your thumb is covering a corner of the paper? Basic scanners fail because they look for 4 corners. Our engine wraps the document in a mathematical Convex Hull, predicting exactly where the missing corner should exist based on the trajectory of the visible edges.

Combined with a massive 1000px static processing matrix, the AIToolYes Scanner Pro is arguably the most powerful native-web scanner in existence.