Skip to main content

Run Length Smoothing Algorithm

Project description

RLSA

C implementation of RLSA for use in python.

Usage

Requirements

  • python version >= 3.8

Install

Install with:

pip install rlsa

Usage

The main function is rlsa.
It takes as input a black and white image (as a uint8 numpy array), and the hvs, vsv and ahvs values. The function returns a new black and white image, leaving the original one intact.

You can also import the rlsa_horizontal and rlsa_vertical functions to apply only one of the RLSA components.

Usage example

A full example would be:

import cv2
from rlsa import rlsa

img = cv2.imread("assets/rlsa_test_image.jpg", cv2.IMREAD_GRAYSCALE)
_, binary_img = cv2.threshold(img, 190, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)

hsv = vsv = 25
out_img = rlsa(binary_img, hsv, vsv, hsv//10)

With a similar setup, the other functions can be used like so:

out_img = rlsa_horizontal(binary_img, hsv)
out_img = rlsa_vertical(binary_img, vsv)

Results

Input image After RLSA
Input Output
Horizontal only Vertical only
Horizontal Vertical

Included scripts

A few scripts are included in the tests folder. One is a python implementation of rlsa, serving as reference. The other two compare the result and speed of the implementations.
To run the those scripts, you need to install opencv.

Test

python -m tests.test assets/rlsa_test_image.jpg

Benchmark

python -m tests.benchmark assets/rlsa_test_image.jpg

--> C version is around 400 times faster than the naive python one.

Misc

Note: the numpy tutorial/doc here is (it seems) outdated (be carefull when using it).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rlsa-0.0.2.tar.gz (5.0 kB view hashes)

Uploaded Source

Built Distributions

rlsa-0.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (25.0 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.24+ x86-64

rlsa-0.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (27.0 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.24+ x86-64

rlsa-0.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (27.6 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.24+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page