How document edge detection works (finding paper in a photo)
· How it works
You see “a paper on a table” instantly. A computer sees six million numbers. Edge detection is the pipeline that turns those numbers into four corner coordinates — and it's a lovely mix of old-school vision math and modern neural nets.
The classical approach: follow the contrast
Classic computer vision finds documents by hunting for boundaries: filters highlight places where brightness changes sharply (edges), an algorithm links edges into contours, and the system asks “which closed contour looks like a big quadrilateral?” It's fast and works beautifully when the paper contrasts with the table — the reason our advice keeps repeating dark background.
The neural approach: learn what documents look like
Neural detectors are trained on huge sets of photographed documents until they output corner positions directly — they've effectively seen more messy desks than any human. They shine exactly where classical logic struggles: cluttered backgrounds, moderate contrast, textured surfaces. Their cost: they can be confidently wrong in weird cases classical logic would flag.
Why ToPDF runs both
ToPDF ensembles the two: a document-specific neural model and a classical detector both propose corners; the proposals are scored (edge contrast along each proposed side, sane geometry, coverage) and the best wins. Crucially, a rectangle that would slice through content or a skewed low-confidence quad isn't silently applied — it routes to the corner editor for your one-tap confirmation. Detection is probabilistic; bad crops shouldn't be.
Frequently asked questions
Why does white-on-white defeat scanners?
Both approaches ultimately need the document to differ from its surroundings. White paper on a white desk offers near-zero boundary signal — physics, not software, is the limiting factor.
Does all this run on my device?
Yes — both detectors are compiled to WebAssembly and execute in your browser tab. The photo never leaves your device for detection or anything else.
Scan it now — free & private
Snap a photo, get a clean auto-cropped PDF in seconds. Everything runs in your browser — your documents never leave your device.
Open the scanner