Uncovering the Handwritten Text in the Margins: End-to-end Handwritten Text Detection and Recognition
Paper Info
| Title | Uncovering the Handwritten Text in the Margins: End-to-end Handwritten Text Detection and Recognition |
| Authors | Liang Cheng, Jonas Frankemölle, Adam Axelsson, Ekta Vats |
| Conference | Proceedings of the 8th Joint SIGHUM Workshop on Computational Linguistics for Cultural Heritage, Social Sciences, Humanities and Literature (LaTeCH-CLfL 2024) |
| Paper | aclanthology: 2024.latechclfl-1.12 |
| Code | GitHub: Project-Marginalia |
Motivation
Libraries and archives worldwide are digitizing their historical collections at a massive scale. The printed text in early books is well-documented and searchable. But what about the handwritten notes in the margins — the marginalia?
Marginalia are a precious historical resource:
- They reveal how earlier readers engaged with texts
- They provide insights into intellectual history, gender studies, and knowledge exploration
- Collections like the Walleriana at Uppsala University Library (dating back to the 1400s) contain rich marginalia that have never been digitally transcribed
Challenges:
- High variability — different writers, centuries, languages, scripts
- Data scarcity — expert annotation is expensive and time-consuming; only 513 labeled pages in our dataset
- Under-explored problem — most HTR research focuses on main text, not marginalia
Pipeline Overview
1 | |
Method Details
1. Data & Preprocessing
| Item | Details |
|---|---|
| Source | Uppsala University Library early book collections (Walleriana) |
| Labeled images | 513 pages, expert-annotated with LabelMe (bounding boxes only) |
| Train/test split | 9:1 |
| Data augmentation | Horizontal flip + Gaussian noise + random brightness/contrast → 1848 training samples |
| Image size | Resized to 350×500 |
2. Marginalia Detection: R-CNN vs Faster R-CNN
R-CNN baseline:
- Region proposals via MSER (Maximally Stable Extremal Regions) — a watershed-based algorithm
- Positive samples: crop from annotated boxes, resize to 227×227
- Negative samples: 4 MSER boxes with IoU=0 per image
- Classifier: AlexNet (5 conv + 2 FC layers, 2 output classes)
- Problem: depends entirely on MSER quality → fails when MSER doesn’t capture full marginalia
Faster R-CNN (our main method):
- Backbone: ResNet-50 (pre-trained)
- RPN (Region Proposal Network) replaces selective search/MSER
- End-to-end training: RPN and Fast R-CNN share convolutional features
- Output: 2 classes (marginalia / non-marginalia) + 4 bounding box coordinates
- Training: 13 epochs, learning rate 0.001
3. Segmentation
Line segmentation:
- Sobel edge detection to emphasize text strokes
- Horizontal projection (sum of pixel values per row)
- Peak detection to find line positions
- Threshold = midpoint between highest peak and lowest value
Word segmentation:
- Binarize each line image
- Vertical projection to find spaces
- Calculate average space width
- Split only on spaces wider than the average
4. Recognition: AttentionHTR
We reuse our previously developed AttentionHTR model (Kass & Vats, 2022):
| Stage | Description |
|---|---|
| TPS Transform | Thin-plate spline transformation to correct text distortion |
| ResNet-32 | 32-layer ResNet for feature extraction |
| 2-layer BiLSTM | Bidirectional LSTM for sequence modeling |
| Attention + Decoder | Content-based attention mechanism with unidirectional LSTM decoder |
Key advantage: Pre-trained on Imgur5K (5000 different writers), so it transfers well to our small dataset with no additional training needed.
Results
Detection Performance
| Model | Performance | IoU | Key Failure Modes |
|---|---|---|---|
| R-CNN | ~90.7% val accuracy | Low | (1) Boxes don’t fully align (2) Only partial marginalia captured (3) Fails on large marginalia |
| Faster R-CNN | Accurate across diverse cases | 0.82 | Robust to large marginalia, figures, and varying layouts |
Why Faster R-CNN wins: It doesn’t depend on pre-segmentation (MSER). The RPN learns to propose relevant regions directly from the image feature map, and the shared convolutional backbone makes it both faster and more accurate.
Segmentation Performance
- Works well when: lines don’t intersect, words are clearly separated
- Fails when:
- Handwriting rows overlap (letters from two lines share the same pixel rows) → whole block detected as one line
- Words are connected by strokes or underlines → can’t separate words
- Root cause: Projection-based methods are purely heuristic and can’t handle complex layouts
Recognition Performance
| Input quality | AttentionHTR performance |
|---|---|
| Clear, well-segmented single word | Very accurate — words and numbers both recognized correctly |
| Blurry/unreadable (even for humans) | Fails — as expected |
| Multiple words in one image | Inaccurate |
Key finding: Recognition accuracy is bounded by segmentation quality. The better the input, the better the output — and AttentionHTR requires zero fine-tuning on our data to work well.
Discussion & Limitations
| Aspect | Discussion |
|---|---|
| Detection bottleneck | R-CNN’s dependence on MSER is its Achilles’ heel; Faster R-CNN solves this cleanly |
| Segmentation bottleneck | Projection-based segmentation is the weakest link in the pipeline |
| Future: better segmentation | Could use R-CNN at the word level too, but requires word-level annotation data |
| Other detectors | Mask R-CNN and YOLO not yet explored; data format is compatible → future work |
| Other recognizers | TrOCR (Transformer-based) not compared; we chose AttentionHTR for its strong pre-trained multi-writer model |
| Language model | Skip-gram or BERT post-processing could improve accuracy but adds compute cost |
| Data limitation | Only bounding box labels, no text annotations → can’t fine-tune the recognizer on our data |
| Generalization | Special scripts (Gothic, curlicue), blurry text, strike-throughs, very poor handwriting remain challenging |
Key Takeaways
- First end-to-end marginalia detection + recognition pipeline — to our knowledge, the first work addressing historical handwritten marginalia as a complete pipeline
- Faster R-CNN is the right tool for detection — IoU 0.82, substantially better than MSER+R-CNN
- Segmentation is the pipeline bottleneck — heuristic projection methods limit overall accuracy
- Transfer learning makes it work with scarce data — pre-trained AttentionHTR handles the recognition side without additional training
- Reproducible and extensible — modular code, adaptable data format, ready for future improvements (Mask R-CNN, YOLO, TrOCR, language models)
One-sentence summary: An end-to-end pipeline combining Faster R-CNN detection, projection-based segmentation, and transfer-learned attention HTR enables automatic extraction of handwritten marginalia from historical books, even with limited training data.
BibTeX
1 | |
All articles in this blog adopt the CC BY-SA 4.0 agreement except for special statements. Please indicate the source for reprinting!