A very fast 2D concave hull algorithm
Project description
concave_hull
A very fast 2D concave hull algorithm.
Credits goes to:
Online document: https://concave-hull.readthedocs.io/en/latest/
Install
via pip
pip install -U concave_hull
from source
git clone --recursive https://github.com/cubao/concave_hull
pip install ./concave_hull
Or
pip install git+https://github.com/cubao/concave_hull.git
(you can build wheels for later reuse by pip wheel git+https://github.com/cubao/concave_hull.git
)
Usage
Signature:
# import
from concave_hull import concave_hull, concave_hull_indexes
# get concave hull indexes
concave_hull_indexes(
points: Union[numpy.ndarray, List, Tuple],
*,
concavity: float = 2.0,
length_threshold: float = 0.0,
# you can just ignore "convex_hull_indexes"
convex_hull_indexes: numpy.ndarray[numpy.int32[m, 1]] = None,
) -> numpy.ndarray[numpy.int32[m, 1]]
# get concave hull points
concave_hull(
points: Union[numpy.ndarray, List, Tuple],
... # same as
) -> Union[numpy.ndarray, List, Tuple]
# P.S., we provide convex_hull (Graham scan)
from concave_hull import convex_hull, convex_hull_indexes
concavity
is a relative measure of concavity. 1 results in a relatively detailed shape, Infinity results in a convex hull. You can use values lower than 1, but they can produce pretty crazy shapes.length_threshold
: when a segment length is under this threshold, it stops being considered for further detalization. Higher values result in simpler shapes.
(document from https://github.com/mapbox/concaveman)
Example (see full code in test.py
):
import matplotlib.pyplot as plt
import numpy as np
from scipy.spatial import ConvexHull
from concave_hull import concave_hull, concave_hull_indexes
points = []
c = np.array([250, 250])
for x in np.arange(100, 400, 5 * np.pi):
for y in np.arange(100, 400, 5 * np.pi):
if x > c[0] and y > c[1]:
continue
r = np.linalg.norm(c - [x, y])
if r > 150:
continue
points.append([x, y])
points = np.array(points)
convex_hull = ConvexHull(points[:, :2]) # it's already N-by-2, I'm just emphasizing
# https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.ConvexHull.html
plt.plot(points[:, 0], points[:, 1], "o")
for simplex in convex_hull.simplices:
plt.plot(points[simplex, 0], points[simplex, 1], "g-", alpha=0.5)
idxes = concave_hull_indexes(
points[:, :2],
length_threshold=50,
)
# you can get coordinates by `points[idxes]`
assert np.all(points[idxes] == concave_hull(points, length_threshold=50))
for f, t in zip(idxes[:-1], idxes[1:]): # noqa
seg = points[[f, t]]
plt.plot(seg[:, 0], seg[:, 1], "r-", alpha=0.5)
# plt.savefig('hull.png')
plt.show()
Tests
make python_install
make python_test
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
concave_hull-0.0.6.tar.gz
(3.2 MB
view hashes)
Built Distributions
Close
Hashes for concave_hull-0.0.6-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdadaf5190b24ee2cdee97803eb070858a4993a078c69022b280a5a87d27a570 |
|
MD5 | 9181f542bfb321b08020710cb6e55c64 |
|
BLAKE2b-256 | 05ba052ee87e110dc6855f446e481af5ffac2d4c46e10e7638845f025aea8218 |
Close
Hashes for concave_hull-0.0.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a43d325fdd12680157ee9ec0051d8f6d9147fdc8021f1caff5d84684aeac00cb |
|
MD5 | cc67a24970e9c6d75643c1babc4484b9 |
|
BLAKE2b-256 | ea29d75d8a5ad9d1cc8265e5c9b5fb2c321e14a726c9f8dc1ae2be84fc299609 |
Close
Hashes for concave_hull-0.0.6-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 111e86b1b7735b38b697dbc1028c2622e8578cb87f8a146c4c67ea966aa84044 |
|
MD5 | 2ee4e316575654c81b80552c8f4adf51 |
|
BLAKE2b-256 | bc8f9c0b9ca55ce1f60c01de8558616d4b2a05fe0054b56e2ea562c6690368fd |
Close
Hashes for concave_hull-0.0.6-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cc0f306c664da01d958a2107dd394a9431a516be35ccbb99f6519a9d3f24a2e |
|
MD5 | ba991bdd5703500f68ba9bc0b4482f30 |
|
BLAKE2b-256 | 9decd9547cd3091ed9eb253dc2a861eed63927dd6e2311d70e24f486414b5266 |
Close
Hashes for concave_hull-0.0.6-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d49c5e913db2fb2b82819a6bc4dd5a243c8e0a9749cfae0bbf633bb896898037 |
|
MD5 | 24570965672ea54b19d6093a7779a487 |
|
BLAKE2b-256 | 1a77c08581d2d167d75eadb280b054a6a64a376572b448f03d7aa7f086c89946 |
Close
Hashes for concave_hull-0.0.6-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8aa54d1e8ae59ea7a6ec140b7df965907d9e1348f18daf72647155edcefcdc6e |
|
MD5 | 0079de8f6d2ae32172b2540f5cf95256 |
|
BLAKE2b-256 | 0ba87d019a225fffa007f3f33ba91253e4ac137140f1baf526753f5c81e2f747 |
Close
Hashes for concave_hull-0.0.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6998330b6d5f6d19634260528b7c119dc1376715fc6593c25995b68d052bccba |
|
MD5 | b690743f1d2a2668f5373345efc1a6a8 |
|
BLAKE2b-256 | f17368dbd42ff8e5cbcd60aa670696b4559199c4e6500200eee91c234e130243 |
Close
Hashes for concave_hull-0.0.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cb9310c946755132f1f8d17054de75aae63734be882fe51c3410825fa1dccbe |
|
MD5 | e2d2270a54a744f99023d6c230f7ef2f |
|
BLAKE2b-256 | 874c082e0b2f2b552dfffac0bafd03600ee79829b4bdd4ba1230ccba0a016ba1 |
Close
Hashes for concave_hull-0.0.6-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac24b79d7c6042d588b760fb1e4df566d75bd132af19f8ad9fc579888114799f |
|
MD5 | 1e6e6add53b076ccc9885c2b8011dd4c |
|
BLAKE2b-256 | 90d384500ace67da3dab9b7e3501830022782c14a91e3f536fef8f650432a987 |
Close
Hashes for concave_hull-0.0.6-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64783678c1cc7840afd30d9f17778187f0ae2f6a88b0a756daf7bb62ac38dae6 |
|
MD5 | 7c01f094409602d0f12d71636ebb8577 |
|
BLAKE2b-256 | 4851718f527c76e33624929c439d96c3c3af6f454dd571b751b7e3a39e5aa46d |
Close
Hashes for concave_hull-0.0.6-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78d58f348c685abbc1b8d5418b834a2c70e447eb99f66bdd7008212033f6d19f |
|
MD5 | 32a14a79bf7dda11323c05ff141187e2 |
|
BLAKE2b-256 | cfab637e3676679e44cf9f7ecc0bc120f0cdbc736256281f58e5cb4da8f0ca06 |
Close
Hashes for concave_hull-0.0.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bceef5e01b1ca15d4dc3fc7aa11a53d0e47debc103c59323f079779c28d4c66 |
|
MD5 | 2d104a93603f2691d668726ffc1e8fac |
|
BLAKE2b-256 | 6395311696a1e2c7696e857593d007d7d18cf4206d48d6b036e94ac2cea82d4f |
Close
Hashes for concave_hull-0.0.6-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cce59369613446865902b9cba0aee7e9ffb3db8c568cd49df2997922816d50b |
|
MD5 | 53fe4a804cf88921840c8c8137b8d262 |
|
BLAKE2b-256 | d3ad9fabcb52efee797f3b81b0bfc28aa85519c8f2000e33f047f1fa0be6424f |
Close
Hashes for concave_hull-0.0.6-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5079d30d600db4cc0ab2a49c3954f79dd1bc066af1e6249b8d7e4037ddcaa5e2 |
|
MD5 | 1ab95b6a82be183d3605edaf964a1fdf |
|
BLAKE2b-256 | 724cb0afcd8daa5a8e714abb5546ba14f0ebab3ffcdcb4ec190a318c4318c32e |
Close
Hashes for concave_hull-0.0.6-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 721405e479c51fe988146000109eb1e8722e4c3c578f71b8e38d2868c5483c09 |
|
MD5 | a37e14ec789a945e420e636960badd1c |
|
BLAKE2b-256 | a849db7b50692e537f2da91a095e436a19b4d93a410aaec468b5d7ff5e630814 |
Close
Hashes for concave_hull-0.0.6-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ac09d0b409f5604b902ff6d5093423b0028d2231fd47a92abc37abc88212f3c |
|
MD5 | 47461ef8f81feee044e7dc8c56e9c95e |
|
BLAKE2b-256 | 86fad643a8860e509298641fbd64101cef1e2e86679b0e074559ec1ba947642c |
Close
Hashes for concave_hull-0.0.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17ef8fcb2eb09905f77fd20247e43ab64146ffe8d81b194c7e2679ec30d0de7e |
|
MD5 | e353f8f495fda4627d0380f1ee2d361b |
|
BLAKE2b-256 | c1ca7e781c1f1e39493f8e0e12cdbd3d1ba78e0ecbced19330b2912e1aeb2910 |
Close
Hashes for concave_hull-0.0.6-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 247f8cb3b69530f97441964577c91f9e9a0665f3aff29bbc3a2ddf393773016d |
|
MD5 | 94734af8c4ccfc0d2524a9e383343220 |
|
BLAKE2b-256 | e742307ec309ed0aa62e9d7f422d700cebe443bdc9a5eaa8a80e9faa77757396 |
Close
Hashes for concave_hull-0.0.6-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6ca2736deb238a9703eea9f5862191bfea0f0ef38f1c0dd101f4e0e21fc9408 |
|
MD5 | fa3fe275cd2035574d650dfef02f41f5 |
|
BLAKE2b-256 | e6354325771d31c68c314acf596d96985aea7a84ed0c12ade00d9e7f4a654335 |
Close
Hashes for concave_hull-0.0.6-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26940c8bc2c7d23f2e9030f4a33843979155aa35819a2473c4344d58cd6719a8 |
|
MD5 | c0a733b0489e1066c633fe902bd4a438 |
|
BLAKE2b-256 | 6ff7f4a06d391005a82902233b2b34929ce82f3b33395282e71eabcd9398a90c |
Close
Hashes for concave_hull-0.0.6-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ced6adcd0a40c7d3e77a44c206705987dd569eb219334e66a3e093b5e45a36d |
|
MD5 | f001cc745ef6eaa95d59107ac2a009ed |
|
BLAKE2b-256 | 4601b9cc93a936b4124948fc138766906fdcdc23c7415fbbd6a4b91b8f4dd006 |
Close
Hashes for concave_hull-0.0.6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c42078e16223850cfdb666090a14c5ec4230cd8157b327ae87c0a905a7cc2fb2 |
|
MD5 | 3b13f98484d43dcf71cfec6969843f21 |
|
BLAKE2b-256 | 30f8a755a82684dec5093cda5700f5706afefdd62bbacb4015fce93fef593223 |
Close
Hashes for concave_hull-0.0.6-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 446bf5a2080de489e8de5117e34685867f0ad939f89e687d11a9d63460e3c525 |
|
MD5 | 02b7721848cafa71c010f0ce7d0f6b04 |
|
BLAKE2b-256 | 60f46bdb0b30ddfaf9118f16dde95d1f0ae904d9e5fbe6af5a18bc88f833c20b |
Close
Hashes for concave_hull-0.0.6-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf8dea57478e345c7cef60b4aba2e35618918a13b297592a5ffbb237d5ad28cf |
|
MD5 | 7ec3480a2b2a2b3d3865fcbe89eb3909 |
|
BLAKE2b-256 | ea7fbe5793c43a7ee94d172899d98336213d1d32c4a627fb373671436c2c23d8 |
Close
Hashes for concave_hull-0.0.6-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81254ce9e7f2b8c13ef8e71ee43703f928ddc254abfae6938e27987787de36bd |
|
MD5 | 858a372a6662f258f469c51d4143a0aa |
|
BLAKE2b-256 | 8516c782626f7f6a84ca5595c7fce46a5b5219833de7b1ac060e527e1ae7e290 |
Close
Hashes for concave_hull-0.0.6-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54a7f24598fab11fbcb33c792ed27036839c47335833601d232a2f8d5d84217b |
|
MD5 | 49a3ea1365b6b988456ba55f560de03d |
|
BLAKE2b-256 | 0df9945de6415f91cfb06dd58cb913da84e06187a6a67b6cfce9382abc1f521e |
Close
Hashes for concave_hull-0.0.6-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46a6664e00f3035b89791f4b5c381c29e2bdd0ad56376122553353b73c374ebc |
|
MD5 | 5f8f1db262df802e0a6f5b0cc557f75d |
|
BLAKE2b-256 | 2a7df96cae487767fdd460351048fd72105dd0edd0279e03017a75f1cac76459 |
Close
Hashes for concave_hull-0.0.6-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3bdf32a7a6ce62273dab32349e4eb8199ebbd6f6c114be7fb311b05a021b4a0 |
|
MD5 | 400c2f7038b8ec0de9b3cdfb89b9615c |
|
BLAKE2b-256 | 112984bf1aa4ecef009181d1d6e433f3aacbdf40d2368ae4b8968ed2054024b4 |