Detect handwritten words in a text-line (classic image processing method).

Overview

Word segmentation

Implementation of scale space technique for word segmentation as proposed by R. Manmatha and N. Srimal. Even though the paper is from 1999, the method still achieves good results, is fast, and is easy to implement. The algorithm takes an image of a line as input and outputs the segmented words.

example

Run demo

Go to the src/ directory and run the script python main.py. The images from the data/ directory (taken from IAM dataset) are segmented into words and the results are saved to the out/ directory.

Documentation

An anisotropic filter kernel is applied to the input image to create blobs corresponding to words. After thresholding the blob-image, connected components are extracted which correspond to words.

Parameters

Most of the parameters of the function wordSegmentation deal with the shape of the filter kernel:

  • img: grayscale uint8 image of the text-line to be segmented.
  • kernelSize: size of filter kernel, must be an odd integer.
  • sigma: standard deviation of Gaussian function used for filter kernel.
  • theta: approximated width/height ratio of words, filter function is distorted by this factor.
  • minArea: ignore word candidates smaller than specified area.

The function prepareImg can be used to convert the input image to grayscale and to resize it to a fixed height:

  • img: input image.
  • height: image will be resized to fit specified height.

Algorithm

The illustration below shows how the algorithm works:

  • top left: input image.
  • top right: filter kernel is applied.
  • bottom left: blob image after thresholding.
  • bottom right: bounding boxes around words in original image.

illustration

Results

This algorithm gives good results on datasets with large inter-word-distances and small intra-word-distances like IAM. However, for historical datasets like Bentham or Ratsprotokolle results are not very good and more complex approaches should be used instead (e.g., a neural network based approach as implemented in the WordDetectorNN repository).

Comments
  • sort_multiline could be improved

    sort_multiline could be improved

    image

    I think that people handwriting will drift randomly but the end of previous word will be about same height as next word. Also words cannot overlap too much in X. Thus the line splitter should compare Y position of words that are near each other in X. The end of previous line not beeing necessarly compared with begining of previous one.

    opened by atsju 15
  • Add requirements ?

    Add requirements ?

    Hi :) I am going to test the software right now and just saw that there are not precise requirements.txt (or equivalent) for dependencies. I think it would be great to make reuse easier :)

    opened by PonteIneptique 2
  • No module named 'word_detector'

    No module named 'word_detector'

    Iam student working on python, was trying with WordDetector, how do i fix this.

    from word_detector import prepare_img, detect, sort_line ModuleNotFoundError: No module named 'word_detector'

    opened by cphmine 1
  • regarding using the image on arbitary pages

    regarding using the image on arbitary pages

    Hello,as mentioned in readme,words should have height in the range of 25-50 pixels.So I am assuming that before feeding the image,it needs to be resized.Any ideas on how to do this.For example: This is from IAM Bern and unfortunately using the current settings the algo fails It also fails if I crop a line from my page and feed it. The line img . page image and the output is enclosed. 6 a01-000x line_output

    opened by gargsp123 1
  • Update WordSegmentation.py

    Update WordSegmentation.py

    According to the paper, shouldn't we be picking sigmaY & then theta being width-to-height aspect ratio of word (theta = SigmaX / SigmaY) giving SigmaX = theta * SigmaY. Certainly getting better results with this approach. Do verify from your side.

    http://ciir.cs.umass.edu/pubfiles/mm-27.pdf

    opened by TheJaeLal 1
  • Not working  properly

    Not working properly

    I have tried it with a scanned image and it is not working properly, the output result is too small that it can't see properly. Also, it is not working for multiple lines.

    opened by aditya8877 1
Owner
Harald Scheidl
Interested in computer vision, deep learning, C++ and Python.
Harald Scheidl
Use Convolutional Recurrent Neural Network to recognize the Handwritten line text image without pre segmentation into words or characters. Use CTC loss Function to train.

Handwritten Line Text Recognition using Deep Learning with Tensorflow Description Use Convolutional Recurrent Neural Network to recognize the Handwrit

sushant097 224 Jan 7, 2023
Deskew is a command line tool for deskewing scanned text documents. It uses Hough transform to detect "text lines" in the image. As an output, you get an image rotated so that the lines are horizontal.

Deskew by Marek Mauder https://galfar.vevb.net/deskew https://github.com/galfar/deskew v1.30 2019-06-07 Overview Deskew is a command line tool for des

Marek Mauder 127 Dec 3, 2022
This can be use to convert text in a file to handwritten text.

TextToHandwriting This can be used to convert text to handwriting. Clone this project or download the code. Run TextToImage.py give the filename of th

Ashutosh Mahapatra 2 Feb 6, 2022
huoyijie 1.2k Dec 29, 2022
Handwritten Text Recognition (HTR) using TensorFlow 2.x

Handwritten Text Recognition (HTR) system implemented using TensorFlow 2.x and trained on the Bentham/IAM/Rimes/Saint Gall/Washington offline HTR data

Arthur Flôr 160 Dec 21, 2022
Handwritten Text Recognition (HTR) system implemented with TensorFlow.

Handwritten Text Recognition with TensorFlow Update 2021: more robust model, faster dataloader, word beam search decoder also available for Windows Up

Harald Scheidl 1.5k Jan 7, 2023
OCR software for recognition of handwritten text

Handwriting OCR The project tries to create software for recognition of a handwritten text from photos (also for Czech language). It uses computer vis

Břetislav Hájek 562 Jan 3, 2023
Apply different text recognition services to images of handwritten documents.

Handprint The Handwritten Page Recognition Test is a command-line program that invokes HTR (handwritten text recognition) services on images of docume

Caltech Library 117 Jan 2, 2023
This is used to convert a string to an Image with Handwritten Characters.

Text-to-Handwriting-using-python This is used to convert a string to an Image with Handwritten Characters. text_to_handwriting(string: str, save_to: s

Akashdeep Mahata 3 Aug 15, 2022
text detection mainly based on ctpn model in tensorflow, id card detect, connectionist text proposal network

text-detection-ctpn Scene text detection based on ctpn (connectionist text proposal network). It is implemented in tensorflow. The origin paper can be

Shaohui Ruan 3.3k Dec 30, 2022
Handwritten Number Recognition using CNN and Character Segmentation

Handwritten-Number-Recognition-With-Image-Segmentation Info About this repository This Repository is aimed at reading handwritten images of numbers an

Sparsha Saha 17 Aug 25, 2022
Official implementation of "An Image is Worth 16x16 Words, What is a Video Worth?" (2021 paper)

An Image is Worth 16x16 Words, What is a Video Worth? paper Official PyTorch Implementation Gilad Sharir, Asaf Noy, Lihi Zelnik-Manor DAMO Academy, Al

null 213 Nov 12, 2022
Detect and fix skew in images containing text

Alyn Skew detection and correction in images containing text Image with skew Image after deskew Install and use via pip! Recommended way(using virtual

Kakul 230 Dec 21, 2022
Tool which allow you to detect and translate text.

Text detection and recognition This repository contains tool which allow to detect region with text and translate it one by one. Description Two pretr

Damian Panek 176 Nov 28, 2022
Detect text blocks and OCR poorly scanned PDFs in bulk. Python module available via pip.

doc2text doc2text extracts higher quality text by fixing common scan errors Developing text corpora can be a massive pain in the butt. Much of the tex

Joe Sutherland 1.3k Jan 4, 2023
A tool combining EasyOCR and LaMa to automatically detect text and replace it with an inpainted background.

EasyLaMa (WIP) This is a tool combining EasyOCR and LaMa to automatically detect text and replace it with an inpainted background. Installation For GP

null 3 Sep 17, 2022