https://huggingface.co/spaces/aabdoo234/fadedTextRestoration
This project restores faded English text from historical documents using digital image processing and OCR techniques. It applies a series of enhancements and evaluates the results at each stage using Tesseract OCR. The extracted texts are then processed by a Gemini LLM, which predicts the original text based on all outputs. Finally, the Levenshtein distance is used to measure accuracy.
The restoration process involves several steps:
- Thresholding
- Adaptive thresholding (Gaussian) or manual thresholding.
- Denoising
- BM3D denoising for noise reduction.
- Median blurring and filtering to remove artifacts.
- Sharpening
- Enhances text visibility using convolution filters.
Tesseract OCR extracts text after each processing step:
- Original Image Text
- Thresholded Image Text
- BM3D Denoised Image Text
- Denoised Image Text
- Sharpened Image Text
A Gemini LLM combines extracted texts to predict the original content. The model is prompted with OCR results from multiple preprocessing techniques to generate a refined text output.
The restoration accuracy is measured using Levenshtein distance, calculated as a percentage comparison between:
- The extracted text and the user-provided transcription (if available), or
- The LLM-generated text.
- Original Image Accuracy
- Thresholded Image Accuracy
- BM3D Denoised Image Accuracy
- Denoised Image Accuracy
- Sharpened Image Accuracy
- Model Response Accuracy
The project includes a Gradio-based web app for interactive restoration:
- Upload an image of a faded text document.
- Adjust thresholding settings (manual or adaptive).
- View processed images and extracted texts.
- Compare accuracy metrics against a correct transcription.
- Generate a refined text output using Gemini LLM.
- Image enhancement previews for each processing step.
- Side-by-side text extraction comparisons.
- Real-time accuracy calculations.
- User-friendly slider and checkbox for thresholding control.
This application is built with Python and requires the following dependencies:
pip install gradio opencv-python numpy pytesseract google-generativeai rapidfuzz