Detect and fix skew in images containing text

Overview

Alyn

PyPI version

Skew detection and correction in images containing text

Image with skew

Image after deskew

Install and use via pip!

Recommended way(using virtualenv):

  1. mkdir alyn-test
  2. cd alyn test
  3. mkvirtualenv .
  4. pip install alyn
  5. source bin/activate

To detect skew angle in image:

from alyn import SkewDetect
sd = SkewDetect(
	input_file='path_to_file',
	batch_path='optional_batch_processing_path',
	output_file='optional_text_file_output_path',
	display_output='Yes/No')
sd.run()
Extra options:
  • sigma:canny edge detection blurring
  • plot_hough: display hough lines detected
  • num_peaks: control the number of hough line peaks

To deskew image:

from alyn import Deskew
d = Deskew(
	input_file='path_to_file',
	display_image='preview the image on screen',
	output_file='path_for_deskewed image',
	r_angle='offest_angle_in_degrees_to_control_orientation')`
d.run()

Requires

  • numpy
  • matplotlib
  • scipy
  • scikit-image

Techniques used

  • Canny Edge Detection
  • Hough Transform

Features

  • Detect the skew in given images
  • Display the output
  • Save the output to txt file
  • Batch process files in a directory
  • View Hough Transform of a given image
  • Set the number of peaks for Hough Transform and Sigma for Canny Edge detection
  • Rotate the image to remove the skew

How the skew detection works

The skew detection script takes image file as input, then performs the following steps:

  • Converts the image to greyscale
  • Performs Canny Edge Detection on the Image
  • Calculates the Hough Transform values
  • Determines the peaks
  • Determines the deviation of each peaks from 45 degree angle
  • Segregates the detected peaks into bins
  • Chooses the probable skew angle using the value in the bins

The deskew script uses the skew angle determined using skew detection script to remove the skew from the image.

Using scripts directly(older method)

Image skew calculation using skew_detect.py

To calculate the skew angle for a given image file, use -i option followed by the path to file:

./skew_detect.py -i image.jpg

To save output in a text file add -o option followed by the output file name:

./skew_detect.py -i image.jpg -o output.txt

To display output information add -d option followed by a string Yes:

./skew_detect.py -i image.jpg -d Yes

To batch process files in a directory, use -b option followed by the path to directory:

./skew_detect.py  -b examples

To display Hough Transform plot for an image,:

./skew_detect.py -i image.jpg -p Yes
Output of the Hough Transform:

To set the value of sigma for Gaussian blurring in Canny Edge Detection, use -s option followed by the desired value:

./skew_detect.py -i image.jpg -s 3

To set the number of peaks collected from Hough Transform, use -n option followed by the desired value:

./skew_detect.py -i image.jpg -n 10

Image Deskew using deskew.py

To perform a simple deskew and display the output:

./deskew.py -i image.jpg -d Yes

To save the deskewed image, use the following:

./deskew.py -i image.jpg -o rotated.jpg

In some cases the result image might be upside down or the text may be running vertical, To fix this, use -r followed by the desired angle in int:

./deskew.py -i image.jpg -o rotated.jpg -r 90

To generate data for experimental purposes, run the test_img_gen.py in test_data folder. This will generate images containing a white line having angle between 0 to 180 degrees.

Owner
Kakul
A Hapless Swiss Army Knife
Kakul
Python Computer Vision from Scratch

This repository explores the variety of techniques commonly used to analyze and interpret images. It also describes challenging real-world applications where vision is being successfully used, both f

Milaan Parmar / Милан пармар / _米兰 帕尔马 221 Dec 26, 2022
Code for CVPR2021 paper "Learning Salient Boundary Feature for Anchor-free Temporal Action Localization"

AFSD: Learning Salient Boundary Feature for Anchor-free Temporal Action Localization This is an official implementation in PyTorch of AFSD. Our paper

Tencent YouTu Research 146 Dec 24, 2022
Packaged, Pytorch-based, easy to use, cross-platform version of the CRAFT text detector

CRAFT: Character-Region Awareness For Text detection Packaged, Pytorch-based, easy to use, cross-platform version of the CRAFT text detector | Paper |

188 Dec 28, 2022
A collection of resources (including the papers and datasets) of OCR (Optical Character Recognition).

OCR Resources This repository contains a collection of resources (including the papers and datasets) of OCR (Optical Character Recognition). Contents

Zuming Huang 363 Jan 03, 2023
https://arxiv.org/abs/1904.01941

Character-Region-Awareness-for-Text-Detection- https://arxiv.org/abs/1904.01941 Train You can train SynthText data use python source/train_SynthText.p

DayDayUp 120 Dec 28, 2022
Automatically fishes for you while you are afk :)

Dank-memer-afk-script A simple and quick way to make easy money in Dank Memer! How to use Open a discord channel which has the Dank Memer bot enabled.

Pranav Doshi 9 Nov 11, 2022
Dirty, ugly, and hopefully useful OCR of Facebook Papers docs released by Gizmodo

Quick and Dirty OCR of Facebook Papers Gizmodo has been working through the Facebook Papers and releasing the docs that they process and review. As lu

Bill Fitzgerald 2 Oct 28, 2021
Learn computer graphics by writing GPU shaders!

This repo contains a selection of projects designed to help you learn the basics of computer graphics. We'll be writing shaders to render interactive two-dimensional and three-dimensional scenes.

Eric Zhang 1.9k Jan 02, 2023
Python package for handwriting and sketching in Jupyter cells

ipysketch A Python package for handwriting and sketching in Jupyter notebooks. Usage A movie is worth a thousand pictures is worth a million words...

Matthias Baer 16 Jan 05, 2023
A curated list of resources dedicated to scene text localization and recognition

Scene Text Localization & Recognition Resources A curated list of resources dedicated to scene text localization and recognition. Any suggestions and

CarlosTao 1.6k Dec 22, 2022
SemTorch

SemTorch This repository contains different deep learning architectures definitions that can be applied to image segmentation. All the architectures a

David Lacalle Castillo 154 Dec 07, 2022
(CVPR 2021) Back-tracing Representative Points for Voting-based 3D Object Detection in Point Clouds

BRNet Introduction This is a release of the code of our paper Back-tracing Representative Points for Voting-based 3D Object Detection in Point Clouds,

86 Oct 05, 2022
scene-linear test images

Scene-Referred Image Collection A collection of OpenEXR Scene-Referred images, encoded as max 2048px width, DWAA 80 compression. All exrs are encoded

Gralk Klorggson 7 Aug 25, 2022
Genalog is an open source, cross-platform python package allowing generation of synthetic document images with custom degradations and text alignment capabilities.

Genalog is an open source, cross-platform python package allowing generation of synthetic document images with custom degradations and text alignment capabilities.

Microsoft 235 Dec 22, 2022
Detect textlines in document images

Textline Detection Detect textlines in document images Introduction This tool performs border, region and textline detection from document image data

QURATOR-SPK 70 Jun 30, 2022
Text language identification using Wikipedia data

Text language identification using Wikipedia data The aim of this project is to provide high-quality language detection over all the web's languages.

Vsevolod Dyomkin 28 Jul 09, 2022
GDB python tool to pretty print and debug c++ xtensor containers

gdb_xt2np GDB python tool to pretty print, examine, and debug c++ Xtensor containers. Xtensor is a c++ library for scientific computing using multidim

Christopher Burke 4 Oct 29, 2021
Textboxes_plusplus implementation with Tensorflow (python)

TextBoxes++-TensorFlow TextBoxes++ re-implementation using tensorflow. This project is greatly inspired by slim project And many functions are modifie

81 Dec 07, 2022
[BMVC'21] Official PyTorch Implementation of Grounded Situation Recognition with Transformers

Grounded Situation Recognition with Transformers Paper | Model Checkpoint This is the official PyTorch implementation of Grounded Situation Recognitio

Junhyeong Cho 18 Jul 19, 2022
PyTorch Re-Implementation of EAST: An Efficient and Accurate Scene Text Detector

Description This is a PyTorch Re-Implementation of EAST: An Efficient and Accurate Scene Text Detector. Only RBOX part is implemented. Using dice loss

365 Dec 20, 2022