Collection of fast polygon operations for DL
Project description
uPolygon (WIP)
Library of handy polygon related functions to speed up machine learning projects.
It was born as a replacement for cv2.fillPoly when generating masks for instance segmentation, without having to bring in all of opencv.
TODO
- draw_polygon
- find_contours
- polygon_area
- point_in_polygon
Usage
This library expects all polygons to be model as a list of paths, each path is a list of alternating x and y coordinates ([x1,y1,x2,y2,...]).
A simple triangle would be declared as:
triangle = [[50,50, 100,0, 0,0]]
Complex polygons (holes and/or disjoints) follow the even-odd rule.
draw_polygon
draw_polygon(mask: array[:, :], paths: path[]) -> array[:, :]
from upolygon import draw_polygon
import numpy as np
mask = np.zeros((100,100), dtype=np.int32)
draw_polygon(mask, [[50,50, 100,0, 0,0]], 1)
Equivalent of calling cv2.fillPoly(mask, [np.array([[50,50], [100,0], [0,0]])], 1) or cv2.drawContours(mask, [np.array([[50,50], [100,0], [0,0]])], -1, 1, cv2.FILLED) when using opencv.
uPolygon is ~ 6 times faster than opencv for large random polygons with many intersecting lines. For smaller polygons or few intersections, uPolygon is half as fast as opencv.
find_contours
find_contours(mask: array[:, :]) -> (array[:, :], path[:], path[:])
0 is treated as background, 1 is treated as foreground.
from upolygon import find_contours
import numpy as np
mask = np.array([
[0, 0, 0, 0, 0],
[0, 1, 1, 1, 0],
[0, 1, 1, 1, 0],
[0, 1, 1, 1, 0]
], dtype=np.uint8)
_labels, external_paths, internal_paths = find_contours(mask)
Similar to OpenCV's cv2.findContours but lacking hierarchies. Also similar to BoofCV's LinearContourLabelChang2004 which is based on the same algorithm.
Note that currently the input mask to find_contour needs to be uint8.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file upolygon-0.1.4.tar.gz.
File metadata
- Download URL: upolygon-0.1.4.tar.gz
- Upload date:
- Size: 297.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.9.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0a17515d6863a5700b2d31d485b8323cc763768ad9ec8138581dc14a34c9578
|
|
| MD5 |
638f7e50016db807742725a6cb1c5abe
|
|
| BLAKE2b-256 |
bc6827809e7860577dbd9f5eac7ce003ab3c0960f7c675809d58c34d6664567d
|
File details
Details for the file upolygon-0.1.4-cp38-cp38-macosx_10_14_x86_64.whl.
File metadata
- Download URL: upolygon-0.1.4-cp38-cp38-macosx_10_14_x86_64.whl
- Upload date:
- Size: 183.6 kB
- Tags: CPython 3.8, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81159d3c68b167c914db651a0b4e507bef9dc07b57d7acfe8f4cd4c8a3781ce4
|
|
| MD5 |
722016f87e945a6fc210a5bd75fc2ce4
|
|
| BLAKE2b-256 |
d6dbde7a44bcc5d524dd92272fd10a5b8225fe81499c69ab48101295e68be0b8
|
File details
Details for the file upolygon-0.1.4-cp37-cp37m-macosx_10_14_x86_64.whl.
File metadata
- Download URL: upolygon-0.1.4-cp37-cp37m-macosx_10_14_x86_64.whl
- Upload date:
- Size: 184.4 kB
- Tags: CPython 3.7m, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49127b5627fdbb495c2a3846f45c2403aab458485c42fba82929c65b90dd18f7
|
|
| MD5 |
1a5b459c042165b90606889a73613c21
|
|
| BLAKE2b-256 |
b7a5b46d6a0dfbd1e65127102c53f4259876e4228a9807e35e2bbf2d4c965126
|
File details
Details for the file upolygon-0.1.4-cp36-cp36m-macosx_10_14_x86_64.whl.
File metadata
- Download URL: upolygon-0.1.4-cp36-cp36m-macosx_10_14_x86_64.whl
- Upload date:
- Size: 183.9 kB
- Tags: CPython 3.6m, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.6.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e62b39aa728672d59e30e12d5f17439fa57c879a832c7e46baaa2d24e13a1dad
|
|
| MD5 |
1c6e360332a60605033de4f42e98cc81
|
|
| BLAKE2b-256 |
37882bc777da3b0427f4837f2470130a4d044c77b614e1fc9f06da2faa500a38
|