Skip to content

A function that takes as input a cropped text line image, and outputs the dewarped image.

Notifications You must be signed in to change notification settings

TomStog/curved-text-alignment

Repository files navigation

Text Line Dewarping

Dependencies

pip3 install -r requirements.txt

NOTE: If you are using pyenv to install older versions of Python, you might need to install development versions of libsqlite3x, ncurses, readline, and tkinter. For example, on Fedora: dnf install libsq3-devel ncurses-devel readline-devel tk-devel.

Running

To process the entire image

Run the dewarp.py script :

python ./dewarp.py ./sample.png ./output.png

To process the image only where there's text

Run the tight_dewarp.py script :

python ./tight_dewarp.py ./sample.png ./output.png

Both functions exhibit comparable performance, with no discernible advantage in either. The primary distinction lies in their operational scope: dewarp.py operates across the entire image, whereas tight_dewarp.py specifically tracks the leftmost and rightmost black pixels within Otsu's threshold image, concentrating its efforts within that identified range.

Steps

  1. Load Image :

Original image

  1. Convert from RGB to Grayscale :

Output image

  1. Apply Otsu's Thresholding Method, Erosion and then Dilation :

Original image

  1. Calculate curve using Generalized Additive Model :

Output image

  1. Final Image :

Output image

Greek Text Example

  1. Input Image :

Output image

  1. Output Image :

Output image

Rectification

  1. Input Image :

Output image

  1. Semi-processed Image :

Output image

  1. Output Image :

Output image

The rectification dataset can be viewed and downloaded through this link.

Citation

If you have found value in this repository, we kindly request that you consider citing it as a source of reference:

Stogiannopoulos, Thomas. “Curved Line Text Alignment: A Function That Takes as Input a Cropped Text Line Image, and Outputs the Dewarped Image.” GitHub, December 1, 2022. https://github.com/TomStog/curved-text-alignment.