Automating document repair often fails because tools either guess wildly or refuse to touch anything ambiguous. Darnleaf, a new local utility built by developer Arthur031221, takes a different approach: it uses SIFT feature matching and RANSAC verification to identify replacement pages, but explicitly marks low-confidence matches as "Check" rather than silently corrupting your archive. The tool addresses a common pain pointβreplacing coffee-stained or creased pages in scanned PDFs with fresh, unordered scansβwhile prioritizing data integrity over blind automation.
The Matching Pipeline
The process begins by rendering every PDF page via PDFium and reducing them to a working size. A preliminary pass uses a sparse subset of SIFT features to shortlist ten candidate pages for each rescan. These candidates undergo rigorous verification using RANSAC under a similarity transform. Crucially, the transform must be physically plausible: the scale factor is constrained between 0.7 and 1.4, and skew is limited to 12 degrees from a right angle. This geometric validation also determines the necessary rotation for the rescan. A one-to-one assignment algorithm resolves conflicts, ensuring that two different rescans cannot claim the same original page.
Confidence Levels and OCR Integration
Darnleaf distinguishes between "Clear" and "Check" matches based on strict criteria. A match is only considered "Clear" if it exhibits sufficient consistent features, strong ink agreement after alignment, and a significant margin over the runner-up candidate. Blank pages, which offer no visual evidence, are always flagged as "Check." While OCR integration can adjust confidence scores, the tool explicitly prevents text matching from creating a match on its own, keeping the decision grounded in visual geometry.
Non-Destructive Export and Audit Trails
When applying changes, Darnleaf swaps pages in place using pikepdf. This approach preserves the original objects for untouched pages and maintains the functionality of bookmarks and internal links that point to replaced pages. For accountability, the tool generates a JSON receipt containing SHA-256 hashes of the original file, the output, and every rescan used. This receipt also logs the specific evidence supporting each swap, providing a clear audit trail for anyone reviewing the repaired document later.
Performance on Synthetic Data
In testing, the tool processed 90 synthetic rescans across ten held-out seeds. Forty-five matches were classified as "Clear," with zero errors among those confirmed matches. However, the developer notes that with 45 trials, the real wrong rate could still statistically hover around 6.7%. The correct page was identified in 89 of the 90 attempts. It is important to note that these tests used rescans generated from the same clean bitmaps as the originals, meaning real-world scans with varying lighting and paper quality will likely yield lower accuracy.
Key Takeaways
- Darnleaf uses SIFT and RANSAC to geometrically verify page matches, rejecting implausible transforms.
- The tool prioritizes honesty, marking ambiguous matches as "Check" instead of forcing a replacement.
- Exports are non-destructive, preserving bookmarks and links while providing a SHA-256 audit receipt.
- Current benchmarks are based on synthetic data; real-world performance may vary due to scan quality.
The Bottom Line
This is how you build trust into automation. By admitting when it doesn't know, Darnleaf avoids the silent data corruption that plagues many "smart" document tools.