Skip to main content

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


Download files

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

Source Distribution

upolygon-0.1.1.tar.gz (268.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

upolygon-0.1.1-cp38-cp38-manylinux2010_x86_64.whl (988.7 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.12+ x86-64

upolygon-0.1.1-cp38-cp38-manylinux1_x86_64.whl (988.7 kB view details)

Uploaded CPython 3.8

upolygon-0.1.1-cp38-cp38-macosx_10_14_x86_64.whl (170.5 kB view details)

Uploaded CPython 3.8macOS 10.14+ x86-64

upolygon-0.1.1-cp37-cp37m-manylinux2010_x86_64.whl (869.9 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.12+ x86-64

upolygon-0.1.1-cp37-cp37m-manylinux1_x86_64.whl (869.9 kB view details)

Uploaded CPython 3.7m

upolygon-0.1.1-cp37-cp37m-macosx_10_14_x86_64.whl (171.0 kB view details)

Uploaded CPython 3.7mmacOS 10.14+ x86-64

upolygon-0.1.1-cp36-cp36m-manylinux2010_x86_64.whl (872.9 kB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.12+ x86-64

upolygon-0.1.1-cp36-cp36m-manylinux1_x86_64.whl (872.9 kB view details)

Uploaded CPython 3.6m

upolygon-0.1.1-cp36-cp36m-macosx_10_14_x86_64.whl (170.3 kB view details)

Uploaded CPython 3.6mmacOS 10.14+ x86-64

File details

Details for the file upolygon-0.1.1.tar.gz.

File metadata

  • Download URL: upolygon-0.1.1.tar.gz
  • Upload date:
  • Size: 268.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for upolygon-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a9a4eb00bc40e3db39dc0f74acf5ade766a98100dca6418d7207b84abbc845df
MD5 45703b03107770b207cc03f4713b5735
BLAKE2b-256 f5358961fd54ac05b009c76dda128903082d2d9b5fedf24def4e65c6e515b0e4

See more details on using hashes here.

File details

Details for the file upolygon-0.1.1-cp38-cp38-manylinux2010_x86_64.whl.

File metadata

  • Download URL: upolygon-0.1.1-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 988.7 kB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for upolygon-0.1.1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 fef0a7d2b09426b7cbd19867f3255dadb0b0a507c24e686946c84a1bccc32493
MD5 7f93eb90e746aefd04e16d884d1093ef
BLAKE2b-256 80293e2c3d6459695d96ad6a1701084c5e8383d11f272dbac2543ec983d48ef0

See more details on using hashes here.

File details

Details for the file upolygon-0.1.1-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: upolygon-0.1.1-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 988.7 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for upolygon-0.1.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7c43608c98eed4b676647c70f0274386dc3d2cfb858b435d310486b38c7faf38
MD5 db15b8211b1b54a0eb153da1ad86ace4
BLAKE2b-256 736d5c399a03ecc52a5c1dd7c9f44b54ed56ba2a1f4f7dfc134f0d047c3a04f0

See more details on using hashes here.

File details

Details for the file upolygon-0.1.1-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: upolygon-0.1.1-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 170.5 kB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for upolygon-0.1.1-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 5f948d464612812a9380afc7207f15e4c55c83a3e4763dec5469171561510334
MD5 4de0fa6dc883d5a43ed62f30f10c8672
BLAKE2b-256 3ec95e02dff6d3630b749b7bfc5db622502a164ad619625d376589a8d213889b

See more details on using hashes here.

File details

Details for the file upolygon-0.1.1-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: upolygon-0.1.1-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 869.9 kB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for upolygon-0.1.1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 1745421105a33866e2e2a00fc9627a1f04bf3c8a17615022a176e155aba8a13c
MD5 3f811af812c85709f503432cfc6c2230
BLAKE2b-256 b0bac2628489aafd75de8d1069d51053f04faeb6df4b6e12736c3f66eacf7568

See more details on using hashes here.

File details

Details for the file upolygon-0.1.1-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: upolygon-0.1.1-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 869.9 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for upolygon-0.1.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 10be0dc7f0d88538166f4b7a5051dd8ff1fe724aedffafea21707820bbee8dd8
MD5 9b843c6c4b2d80c342113ed66c2f9893
BLAKE2b-256 c4150e84831550989301778d5f70f62f6e32af6941840b68d97aa9ba01729337

See more details on using hashes here.

File details

Details for the file upolygon-0.1.1-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: upolygon-0.1.1-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 171.0 kB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.9

File hashes

Hashes for upolygon-0.1.1-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 beab8228969c91f2080e2afab066475fe1c37b4cb4f42b493defcadec4f077e5
MD5 4f2dd71d24ed467439db41049592947c
BLAKE2b-256 ecf182e23a9e95168f9b64f30250a48b0fd461a3d6ef86f7d4fe16ba03c6873a

See more details on using hashes here.

File details

Details for the file upolygon-0.1.1-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: upolygon-0.1.1-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 872.9 kB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for upolygon-0.1.1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 082762744b2cd354ba509c31f876d4fb77b78cc80a9ae28be54750fcfe67bdd1
MD5 a6bb24891141100846fcfbc210556298
BLAKE2b-256 e1de290c1d36e91d4473a8621233a449e4e64d4287bf50d915e8979c16a8454e

See more details on using hashes here.

File details

Details for the file upolygon-0.1.1-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: upolygon-0.1.1-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 872.9 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for upolygon-0.1.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 2ea58717e7c1b80f985683b4b0f099d77a4846ff0d25c3360e8196060263d8b1
MD5 e015607042da1ca83fc95c81be9dd6ed
BLAKE2b-256 5c348284b2e9dadc9acc0cfb96a838956be2899caf3f9d8354d78d1386582441

See more details on using hashes here.

File details

Details for the file upolygon-0.1.1-cp36-cp36m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: upolygon-0.1.1-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 170.3 kB
  • Tags: CPython 3.6m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.6.12

File hashes

Hashes for upolygon-0.1.1-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 8035004430c92f2476a9c458e9614cbcb270c0923d95d898cccec68457179157
MD5 85641499245142ddc440a1b00fc19d2b
BLAKE2b-256 d3552358abf2d9da8b69e922e32b8e4643d9902063e3ca76b56c15ca53e64c63

See more details on using hashes here.

Supported by

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