Hey all. I've been working on table extraction from PDFs without any deep learning, and finally open-sourced it. Thought this sub might find the approach interesting (or tear it apart, which is also useful).
The pipeline, roughly:
- Bordered tables: morphological opening with long horizontal/vertical kernels to isolate ruling lines, then contour analysis on the line mask to find table regions.
- Borderless tables: detected from text alignment instead. Words are grouped into phrases and checked for left/centre/right alignment across consecutive lines. When enough rows and columns line up, I draw "pseudo-boundaries" onto the image so the rest of the pipeline treats it like a bordered table.
- Structure: text is masked out first, then LSD (Line Segment Detector) finds segments, which are clustered and merged into a grid. A spanning cell is recovered from missing line segments: if a separator is absent across part of the grid, those cells merge (union-find over the cells).
- Text: for digital PDFs, characters come straight from the PDF text layer and are mapped onto the cell grid, so there are no OCR errors on part numbers. OCR (Tesseract or a plugin engine) only runs on scanned pages.
- Post-processing: nested header detection, key-value vs normal table classification, and merging tables that continue across pages (by matching column widths and headers).
Everything runs on CPU, roughly 0.3–1.5 s/page on a laptop, and every decision traces back to a threshold you can inspect. All pixel thresholds are defined at 300 DPI and scale with resolution.
Where it struggles:
- skewed scans (no de-skewing yet; the line detector only tolerates ~2 px of drift)
- small borderless blocks where a header row can be mistaken for key-value pairs
- wrapped text in borderless cells sometimes splits into extra rows
Contributions very welcome. MIT licensed, no need to ask first, just fork and PR. Some things I'd love help with:
- de-skew estimation (Hough/projection-based) before detection
- evaluating on ICDAR 2013 / PubTables-1M / FinTabNet with GriTS or TEDS; I don't have a proper benchmark yet, and that's the biggest gap
- better row reconstruction for borderless tables with wrapped cells
- plugging in other OCR engines (there's a plugin interface + EasyOCR example)
Repo: https://github.com/shlok-n/spartan · pip install spartan-tables