Skip to main content
  • RUN LENGTH SMOOTHING ALGORITHM(RLSA) is a method mainly used for block segmentation and text discrimination.
  • It is mainly used in Document Image Processing to extract out the ROI(region of interest) like block-of-text/title/content with applied heuristics.
  • Read the application of RLSA here -> Extract Title from the Image documents in python

Latest Updates

- now rlsa function accepts single value/tuple with pair of values. (before we need to call the function twice)
- a single value be assign to both operations.
- a tuple pair of values be assign to horizontal and vertical operations respectively
- package has a method rlsa_fast that can perform Run Length Smoothing in real time for operations where time is a constraint

Install

- pip install pythonRLSA

Install from Source

- python setup.py install

Install requirements

- pip install -r requirements.txt

Function Calls Snippet - Various Combinations

from pythonRLSA import rlsa

rlsa.rlsa(image_binary, True, True, (10,5)) # passing different values for H and V operations
rlsa.rlsa(image_binary, True, True, [10,5]) # passing different values for H and V operations
rlsa.rlsa(image_binary, True, True, (10)) # passing same value but in tuple
rlsa.rlsa(image_binary, True, True, [10]) # passing same value but in list
rlsa.rlsa(image_binary, True, True, 10) # passing same value as int
rlsa.rlsa(image_binary, True, False, 10.0) # passing same value as float
rlsa.rlsa(image_binary, False, True, 10) # passing same value as int for V operation only

* H - Horizontal
* V - Vertical

- At the end of the readme, ipython snippet is attached
from pythonRLSA.rlsa_fast import rlsa_fast

H_V = rlsa_fast(image_binary, True, True, 10) # performing Horizontal and Vertical operations
H = rlsa_fast(image_binary, True, False, 10) # performing Horizontal operation
V = rlsa_fast(image_binary, False, True, 10) # performing Vertical operation

Input & Output

Output of 3 cases with value "10" can be seen in the below image

Input&Output

More sample images can be seen here

How it works

- '255'(white pixel) wil be converted to '0'(black pixel) in a image, if the number of adjacent 255's are less than the predefined limit "value".
- The "value" varies among the different images.

Sample Test Case

- value = 3
- input - [0, 0, 255, 255, 255, 0, 0, 255, 0, 0, 255, 0, 255]
- output - [0, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 255]

To test

- python pythonRLSA/test_rlsa_unittest.py -v
- python rlsa_fast/test_rlsafast_unittest.py -v

Unittest Results

$ test_bool (__main__.TestRLSA) ... ok
$ test_image (__main__.TestRLSA) ... Image must be an numpy ndarray and must be in binary ... ok
$ test_rlsa_hori (__main__.TestRLSA) ... ok
$ test_rlsa_hori_vert (__main__.TestRLSA) ... ok
$ test_rlsa_vert (__main__.TestRLSA) ... ok
$ test_value (__main__.TestRLSA) ... ok

Ran 6 tests in 0.003s

OK

Prerequisites

- python3.5+
- Image must be a binary ndarray(255's/1's/0's)
- Must pass a predefined limit, a certain integer "value"

Method

- rlsa
- rlsa_fast

Parameters

- image - numpy.ndarray(required)
- horizantal - boolean(required)
- vertial - boolean(required)
- value - any positive integer(int)/list/tuple(required)

IPython snippet to convert Image to Binary and RLSA usage

# convert the image to binary
import cv2
image = cv2.imread('test_images/image.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
(thresh, image_binary) = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
# function call
from pythonRLSA import rlsa
image_rlsa_horizontal = rlsa.rlsa(image_binary, True, False, 10)
image_rlsa_horizontal_vertical = rlsa.rlsa(image_binary, True, True, [10,5])

Bugs/Errors

Please ensure that you have updated pip to the latest version before installing pythonRLSA.

If you find any bugs/errors in the usage of above code, please raise an issue through Github or send an email to vasista.1245@gmail.com with a clear example that can reproduce the issue.

Metadata

Release files for pythonRLSA 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pythonRLSA 1.0.0
File Size Uploaded
pythonRLSA-1.0.0.tar.gz 3.8 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for pythonRLSA 1.0.0
File Interpreter ABI Platform
pythonRLSA-1.0.0-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details

Total release size: 7.7 MB

Release files / pythonRLSA-1.0.0.tar.gz

Download URL pythonRLSA-1.0.0.tar.gz
Size 3.8 MB
Tags Source
SHA-256 checksum
How to use checksums
1c482c7567cf26b64dd1a1793671eef50bdacc79107a5d2308e84873846ad6ae
BLAKE2b-256 checksum
How to use checksums
4614b46615db74ca27a384a0c6a1927b63f87cd95e098641d58edac3640dbe1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.3

Release files / pythonRLSA-1.0.0-cp37-cp37m-win_amd64.whl

Download URL pythonRLSA-1.0.0-cp37-cp37m-win_amd64.whl
Size 3.8 MB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
f02be5dee6c6f829710e05c6573ca759068b90fe1b703331fd36767fdc4afb66
BLAKE2b-256 checksum
How to use checksums
1768b1f45c8db034511a03cb207189430c0893241fc43391ddbde1bab2b7f9d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.3

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.0.2

1 release file

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page