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
Hashes for upolygon-0.1.1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fef0a7d2b09426b7cbd19867f3255dadb0b0a507c24e686946c84a1bccc32493 |
|
MD5 | 7f93eb90e746aefd04e16d884d1093ef |
|
BLAKE2b-256 | 80293e2c3d6459695d96ad6a1701084c5e8383d11f272dbac2543ec983d48ef0 |
Hashes for upolygon-0.1.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c43608c98eed4b676647c70f0274386dc3d2cfb858b435d310486b38c7faf38 |
|
MD5 | db15b8211b1b54a0eb153da1ad86ace4 |
|
BLAKE2b-256 | 736d5c399a03ecc52a5c1dd7c9f44b54ed56ba2a1f4f7dfc134f0d047c3a04f0 |
Hashes for upolygon-0.1.1-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f948d464612812a9380afc7207f15e4c55c83a3e4763dec5469171561510334 |
|
MD5 | 4de0fa6dc883d5a43ed62f30f10c8672 |
|
BLAKE2b-256 | 3ec95e02dff6d3630b749b7bfc5db622502a164ad619625d376589a8d213889b |
Hashes for upolygon-0.1.1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1745421105a33866e2e2a00fc9627a1f04bf3c8a17615022a176e155aba8a13c |
|
MD5 | 3f811af812c85709f503432cfc6c2230 |
|
BLAKE2b-256 | b0bac2628489aafd75de8d1069d51053f04faeb6df4b6e12736c3f66eacf7568 |
Hashes for upolygon-0.1.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10be0dc7f0d88538166f4b7a5051dd8ff1fe724aedffafea21707820bbee8dd8 |
|
MD5 | 9b843c6c4b2d80c342113ed66c2f9893 |
|
BLAKE2b-256 | c4150e84831550989301778d5f70f62f6e32af6941840b68d97aa9ba01729337 |
Hashes for upolygon-0.1.1-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | beab8228969c91f2080e2afab066475fe1c37b4cb4f42b493defcadec4f077e5 |
|
MD5 | 4f2dd71d24ed467439db41049592947c |
|
BLAKE2b-256 | ecf182e23a9e95168f9b64f30250a48b0fd461a3d6ef86f7d4fe16ba03c6873a |
Hashes for upolygon-0.1.1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 082762744b2cd354ba509c31f876d4fb77b78cc80a9ae28be54750fcfe67bdd1 |
|
MD5 | a6bb24891141100846fcfbc210556298 |
|
BLAKE2b-256 | e1de290c1d36e91d4473a8621233a449e4e64d4287bf50d915e8979c16a8454e |
Hashes for upolygon-0.1.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ea58717e7c1b80f985683b4b0f099d77a4846ff0d25c3360e8196060263d8b1 |
|
MD5 | e015607042da1ca83fc95c81be9dd6ed |
|
BLAKE2b-256 | 5c348284b2e9dadc9acc0cfb96a838956be2899caf3f9d8354d78d1386582441 |
Hashes for upolygon-0.1.1-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8035004430c92f2476a9c458e9614cbcb270c0923d95d898cccec68457179157 |
|
MD5 | 85641499245142ddc440a1b00fc19d2b |
|
BLAKE2b-256 | d3552358abf2d9da8b69e922e32b8e4643d9902063e3ca76b56c15ca53e64c63 |