SWTloc : Stroke Width Transform Text Localizer
| Header | Status |
|---|---|
| Latest Release | |
| Downloads | |
| Supported Python | |
| Documentation | |
| Open Issues | |
| License |
Description
This repo contains a python implementation structured as a python package pertaining to the text localization method as in a natural image as outlayed in the Research Paper :-
This library extends the transformation stage of the image for textual content by giving the ability to :
- Localize
Letter's : throughSWTImage.localizeLetters - Localize
Words's, via fusing individualLetter's : throughSWTImage.localizeWords
The process flow of is depicted in the image below :
Installation
pip install swtloc
Documentation
Documentation for SWTLoc can be found at - SWTLoc Documentation
Speed Benchmarking
Below is the speed comparison between different versions of SWTLoc and their various engines. The time measured for
each test image was calculated based on 10 iterations of 10 runs each. Test Images can be found in examples/images/
folder in this repository, and the code for generating the below table can be found in -
Improvements-in-v2.0.0.ipynb notebook in examples/ folder.
| Test Image | SWT v1.1.1 (Python) | SWT v1.1.1 (Python) [x] | SWT v2.0.0 (Python) | SWT v2.0.0 (Python) [x] | SWT v2.0.0 (numba) | SWT v2.0.0 (numba) [x] |
|---|---|---|---|---|---|---|
| test_img1.jpg | 16.929 seconds | 1.0x | 8.145 seconds | 2.078x | 0.33 seconds | 51.315x |
| test_img2.jpg | 10.107 seconds | 1.0x | 4.205 seconds | 2.404x | 0.178 seconds | 50.904x |
| test_img3.jpg | 4.545 seconds | 1.0x | 2.701 seconds | 1.683x | 0.082 seconds | 55.625x |
| test_img4.jpeg | 7.626 seconds | 1.0x | 3.992 seconds | 1.91x | 0.142 seconds | 53.859x |
| test_img5.jpg | 17.071 seconds | 1.0x | 7.554 seconds | 2.26x | 0.302 seconds | 56.62x |
| test_img6.jpg | 4.973 seconds | 1.0x | 3.104 seconds | 1.602x | 0.094 seconds | 53.076x |
Frequently Used Code Snippets
Performing Stroke Width Transformation
# Installation
# !pip install swtloc
# Imports
import swtloc as swt
# Image Path
imgpath = 'examples/images/test_image_5/test_img5.jpg'
# Result Path
respath = 'examples/images/test_image_5/usage_results/'
# Initializing the SWTLocalizer class with the image path
swtl = swt.SWTLocalizer(image_paths=imgpath)
# Accessing the SWTImage Object which is housing this image
swtImgObj = swtl.swtimages[0]
# Performing Stroke Width Transformation
swt_mat = swtImgObj.transformImage(text_mode='db_lf')
Localizing & Annotating Letters and Generating Crops of Letters
# Installation
# !pip install swtloc
# Imports
import swtloc as swt
from cv2 import cv2
import numpy as np
# Image Path
imgpath = 'examples/images/test_image_1/test_img1.jpg'
# Read the image
img = cv2.imread(imgpath)
# Result Path
respath = 'examples/images/test_image_1/usage_results/'
# Initializing the SWTLocalizer class with a pre loaded image
swtl = swt.SWTLocalizer(images=img)
swtImgObj = swtl.swtimages[0]
# Perform Stroke Width Transformation
swt_mat = swtImgObj.transformImage(text_mode='db_lf',
maximum_angle_deviation=np.pi/2,
gaussian_blurr_kernel=(11, 11),
minimum_stroke_width=5,
maximum_stroke_width=50,
display=False) # NOTE: Set display=True
# Localizing Letters
localized_letters = swtImgObj.localizeLetters(minimum_pixels_per_cc=950,
maximum_pixels_per_cc=5200)
letter_labels = [int(k) for k in list(localized_letters.keys())]
# Some Other Helpful Letter related functions
# # Query a single letter
from swtloc.configs import (IMAGE_ORIGINAL,
IMAGE_SWT_TRANSFORMED)
loc_letter, swt_loc, orig_loc = swtImgObj.getLetter(key=letter_labels[5])
# # Iterating over all the letters
# # Specifically useful for jupyter notebooks - Iterate over all
# # the letters, at the same time visualizing the localizations
letter_gen = swtImgObj.letterIterator()
loc_letter, swt_loc, orig_loc = next(letter_gen)
# # Generating a crop of a single letter on any of the available
# # image codes.
# # Crop on SWT Image
swtImgObj.saveCrop(save_path=respath,crop_of='letters',crop_key=6, crop_on=IMAGE_SWT_TRANSFORMED, crop_type='min_bbox')
# # Crop on Original Image
swtImgObj.saveCrop(save_path=respath,crop_of='letters',crop_key=6, crop_on=IMAGE_ORIGINAL, crop_type='min_bbox')
Localizing & Annotating Words and Generating Crops of Words
# Installation
# !pip install swtloc
# Imports
import swtloc as swt
# Image Path
imgpath = 'images/test_img2/test_img2.jpg'
# Result Path
respath = 'images/test_img2/usage_results/'
# Initializing the SWTLocalizer class with the image path
swtl = swt.SWTLocalizer(image_paths=imgpath)
swtImgObj = swtl.swtimages[0]
# Perform Stroke Width Transformation
swt_mat = swtImgObj.transformImage(maximum_angle_deviation=np.pi/2,
gaussian_blurr_kernel=(9, 9),
minimum_stroke_width=3,
maximum_stroke_width=50,
include_edges_in_swt=False,
display=False) # NOTE: Set display=True
# Localizing Letters
localized_letters = swtImgObj.localizeLetters(minimum_pixels_per_cc=400,
maximum_pixels_per_cc=6000,
display=False) # NOTE: Set display=True
# Calculate and Draw Words Annotations
localized_words = swtImgObj.localizeWords(display=True) # NOTE: Set display=True
word_labels = [int(k) for k in list(localized_words.keys())]
# Some Other Helpful Words related functions
# # Query a single word
from swtloc.configs import (IMAGE_ORIGINAL,
IMAGE_SWT_TRANSFORMED)
loc_word, swt_loc, orig_loc = swtImgObj.getWord(key=word_labels[8])
# # Iterating over all the words
# # Specifically useful for jupyter notebooks - Iterate over all
# # the words, at the same time visualizing the localizations
word_gen = swtImgObj.wordIterator()
loc_word, swt_loc, orig_loc = next(word_gen)
# # Generating a crop of a single word on any of the available
# # image codes
# # Crop on SWT Image
swtImgObj.saveCrop(save_path=respath, crop_of='words', crop_key=9, crop_on=IMAGE_SWT_TRANSFORMED, crop_type='bubble')
# # Crop on Original Image
swtImgObj.saveCrop(save_path=respath, crop_of='words', crop_key=9, crop_on=IMAGE_ORIGINAL, crop_type='bubble')
Metadata
Release files for swtloc 2.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| swtloc-2.1.1.tar.gz | 41.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| swtloc-2.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 83.8 kB
Release files / swtloc-2.1.1.tar.gz
| Download URL | swtloc-2.1.1.tar.gz |
|---|---|
| Size | 41.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f57b09b63619a631e149278720a55cefff4d313a76703fed6a9f6a676964139f
|
|
BLAKE2b-256 checksum How to use checksums |
3680e353cdc6643c34a9e1cd25409f9fd2e3bccf4353db424624a10b3e14aca7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.13
|
Release files / swtloc-2.1.1-py3-none-any.whl
| Download URL | swtloc-2.1.1-py3-none-any.whl |
|---|---|
| Size | 42.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a8a3c646ce8a739de8378e5cdb0c6f90253ae75783e5a80a720bbafe07e69821
|
|
BLAKE2b-256 checksum How to use checksums |
aed52f40a7289f783766183bf1a939f771be90ed50151a1effbf47e941f931fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.13
|