A very fast 2D concave hull algorithm
Project description
concave_hull
A very fast 2D concave hull algorithm.
Credits goes to:
Install
via pip
pip install 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:
# get concave hull indexes
concave_hull_indexes(
points: Union[numpy.ndarray, List, Tuple],
*,
concavity: float = 2.0,
length_threshold: float = 0.0,
convex_hull_indexes: numpy.ndarray[numpy.int32[m, 1]] = None, # will use integrated scipy ConvexHull if None
) -> numpy.ndarray[numpy.int32[m, 1]]
# get concave hull points
concave_hull(
points: Union[numpy.ndarray, List, Tuple],
*args, *kwargs # will proxy all to covcave_hull_indexes
) -> Union[numpy.ndarray, List, Tuple]
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,
# for concave_hull>=0.0.3
# it's not necessary to provide convex_hull_indexes
# convex_hull_indexes=convex_hull.vertices.astype(np.int32),
)
# 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.5.tar.gz
(3.2 MB
view hashes)
Built Distributions
Close
Hashes for concave_hull-0.0.5-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46241f48b8a814db105d90eaf949d7ec30f3efd66ea59a97593648bf0d2e86fc |
|
MD5 | 7d01c44ad022abcf4947838ed5b2f767 |
|
BLAKE2b-256 | 30217dd1667ce3e899bc9cd24ec2442c5a4fb186be25a718e5ea7aafc5c78a9b |
Close
Hashes for concave_hull-0.0.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f6114009ac5fec8d76bc766dff5241bf090fb1af0b4e835efd200b0e2393c6c |
|
MD5 | 224056befbe95c60ff9bd1a10ce8ebb4 |
|
BLAKE2b-256 | 8548633989c42b3db3f861e851a40fbb2e657813f18d67383ef6d3e911c420e3 |
Close
Hashes for concave_hull-0.0.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f7c0656f888db4bbae192210f4e860ce13e41026edf842b0761114534dd9a14 |
|
MD5 | 8c1df014a8c1056cfcb99189e710c4fe |
|
BLAKE2b-256 | 25a2f995cd92a37ba10051d8ff12599d6784aa5369c6488ca27e07e0b57879c2 |
Close
Hashes for concave_hull-0.0.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 731db6dc689a94b705f57c71827ebdb03c2ac0984c9311df95503d44b39c7aae |
|
MD5 | af4c35bc2dfdf53ac1e16866b242ef22 |
|
BLAKE2b-256 | c97a62f0955b4d240d35a7bce95b771244feff5390723bddc6faeaa4bf7c7fbb |
Close
Hashes for concave_hull-0.0.5-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f17558f87c34b322f17876ccf19cba3242ff327080822ecb8bc6217a18131a2 |
|
MD5 | 72958a3903ca89df37661bbcf3acba23 |
|
BLAKE2b-256 | eca1afc29e0c8bb1f24abc281ec536ae92fc900a6995aa1840ea9f5715073411 |
Close
Hashes for concave_hull-0.0.5-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c918f994f539712949a949e87248721a794ca01ad0c65aa7e58942ad0cf02b3 |
|
MD5 | c3f0124a521e3aae08b445d8cbbfc4b4 |
|
BLAKE2b-256 | 842ab9b129e22b69d24818b92ea51bf2247b90379a41320455afbf9916c2ac55 |
Close
Hashes for concave_hull-0.0.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cefc46e131bb9401dc867e65f8facca5e57cc992145b7798b72b990850ad8a96 |
|
MD5 | 26f43b04eb1e2465635ec2360368ddb1 |
|
BLAKE2b-256 | 5e8f9eb4e70a2268516307868d0c811dcae45d81f9baf9fa82bfa5e5c379d5d5 |
Close
Hashes for concave_hull-0.0.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c50aadc7a8915055335acb349595171524acb9f3c61e4c281f48dd88c3db39d |
|
MD5 | cc045a9083080b44a553124249a55b13 |
|
BLAKE2b-256 | 4a6a65d29b6e391d6ecd93f9b47b7525efe4b50ec1c66148ba5ab3b2a9610089 |
Close
Hashes for concave_hull-0.0.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1fb4843bdb7e2ef7e6cf41efbb47b01b64fcacace7571ba793823158b5ce13f |
|
MD5 | ea8b1091c66203a4b99febc41bab3ff5 |
|
BLAKE2b-256 | 6b77908ef0428ae612185f53eb789212f1b21de2f3d672f4126d14c22b2f6861 |
Close
Hashes for concave_hull-0.0.5-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 068b5a1917742ee851ba2d67e304561b55aad5474cb031ba57e563d1a60f1c2a |
|
MD5 | 3379e1ceed74eb3f3c8564294ff46b8a |
|
BLAKE2b-256 | a56fc2cf5f8071acd552c0895f037fb448e3230b30a61678991b9feec0459857 |
Close
Hashes for concave_hull-0.0.5-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c084e8e138a66309ae60b7d244b776e33013cc6fd4bde9f7c9ca7433e0e8334 |
|
MD5 | 19de17255c95c7df0b65821781bc797a |
|
BLAKE2b-256 | 860613af2813a9aba58647b2f1a83536b50dc80dc2915835d82ba6f20a30df3d |
Close
Hashes for concave_hull-0.0.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4b4d33557936281630667b05a798ddcb0212a3ea21a3a1a6a8c18c548ee9e4a |
|
MD5 | 2b246d11d3896aad7d87b37796894b52 |
|
BLAKE2b-256 | 7f0db5d4358d26058d00d0bed62bd1d7b9204de76ba21b8ded84e86e4ac2bf70 |
Close
Hashes for concave_hull-0.0.5-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab138e42fb59efb367e8a27b71ed049672a969f6e5a00205711701a41db1031b |
|
MD5 | 5279a65c812012823551626ebcaaa00d |
|
BLAKE2b-256 | abe45f0719b5783a9f69287b34fcd66438db78266695ba1379163d99a365af9f |
Close
Hashes for concave_hull-0.0.5-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4078f7df3ce7c6a57d1c23a4a3a83e5b41f0d3291a3bb0170a15ed99c80ad325 |
|
MD5 | 12fd3ce0702f97dbd99380c2e6dc7ede |
|
BLAKE2b-256 | 34e3798cb463b5f810a2b54bc169afcfe6d02a2007f7c02b8e7573610863fefa |
Close
Hashes for concave_hull-0.0.5-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b15a60da505d7234bf3f213d0e8a5f282889d0125e6f15d139f67d30b83c359 |
|
MD5 | fb93b5e33611feb521740f78b2a321da |
|
BLAKE2b-256 | 0fa8a82de9671f47ee730f15aac2f78fe674464dc0391efe5dcfc1f5085658a9 |
Close
Hashes for concave_hull-0.0.5-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78b646490109c50f47bea9fdff5ce969d36f4d0935bd9c4eb32f51d9b2238b5e |
|
MD5 | 3cfe55f963f5fc167ed1329b2691744d |
|
BLAKE2b-256 | 4855664a0d2e426953b6c332bd8428024695bafe10dc51dcdaa9dab33fd34f8e |
Close
Hashes for concave_hull-0.0.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 908c33341aef1ece5ad8b9f875667f2a18eb88a532fa18030f7b77537a02d4f6 |
|
MD5 | d8ca5a97ab82453bf3e0063f97db3c7a |
|
BLAKE2b-256 | 306bf3c36b64ad818eacc4182cb753049c2bcfadc5dc12529a38d6baef8e78ff |
Close
Hashes for concave_hull-0.0.5-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a6537a7286fda6538e1977d5eed41c28566f3e73d9897977d9bc54d5e8660dd |
|
MD5 | a90c31155d59a1e3facf4082aa4dafd7 |
|
BLAKE2b-256 | 47d51ca0e812e690038117cac29b36b5f3b66150c9d65a0d1bfe4304becacf21 |
Close
Hashes for concave_hull-0.0.5-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 382c3855e87c0ac0a497939b8de39b36dd94b30cb8474d3508d0532ecd106bd3 |
|
MD5 | 58f638aaea34f7feee64911182525b90 |
|
BLAKE2b-256 | 643eacbad17582895f2c6fb545f8e6aacc03261e431c76a17f0d3bcbc4048f80 |
Close
Hashes for concave_hull-0.0.5-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b263ec708cd147d843f420ef8bfbd4aa435a119c82708b53fed1be08bc63be4 |
|
MD5 | 709efcb35ef22b5aa48f1dd747aa17d2 |
|
BLAKE2b-256 | 87d9c5897fb811a107d4bafadf5f71722c940a66f3c7f58886fc1aefa9826034 |
Close
Hashes for concave_hull-0.0.5-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91db49c4546b0e11e074d7598cf458ce1e1409d77eb8e6414c10cd14e3d7fcfc |
|
MD5 | 3f03c2badaf9417e19f4b88d661ba44a |
|
BLAKE2b-256 | 1ed9890a0d758d580eb36f0f3fa575ba454ff3659c563209dc6b2255ed1d77db |
Close
Hashes for concave_hull-0.0.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6937cd504bd6ea7b31ada0acbc5fb4d5a53a6efaf9ccc4d14830bbeeac64f98 |
|
MD5 | e766d076075d785544822a7d8cea28ac |
|
BLAKE2b-256 | ee982c06ff535ba2af044a2ecb94d1491647ae6a29d3a05bf8c6fac9f865e662 |
Close
Hashes for concave_hull-0.0.5-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9162d748e757723da3f6d9f6ed5a85f5ece16af2acb3b554a89c5b90eecc42d6 |
|
MD5 | 385b424855647f97f0941683e448b36a |
|
BLAKE2b-256 | 5e54dec3e9dae846fc748f38dc5719e1f9c4c98241a7f96f1ffa8cf0e0608594 |
Close
Hashes for concave_hull-0.0.5-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4339b54cd85c65be0079a9196140c73451d9da565305c115360db80ff119fa38 |
|
MD5 | 41a081d31fedc78859e1f5a4aaa6c70d |
|
BLAKE2b-256 | f96d958ae2360165a8c09e9b0def30691cb33d232a493039a8001034925c291c |
Close
Hashes for concave_hull-0.0.5-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a27b881e63ebeeba7e3e23a3a4ffca6714655fbb25041753a20f8160d559e96b |
|
MD5 | d1cc969021000c1822bd8d7656712174 |
|
BLAKE2b-256 | b035145de9e888ff0e054199193ef5077281a13f01c6785a31ba5d368af5e058 |
Close
Hashes for concave_hull-0.0.5-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48f043c4a851187005d7c2a9e7f744559183c68610acf968d0b4220159884b47 |
|
MD5 | 0fd11b4d6c173aa784691ea63756ca23 |
|
BLAKE2b-256 | 5f864092c5358b228b53e2d89d55980714a4d4db3c5a929486aa7bd1fa84bbc7 |
Close
Hashes for concave_hull-0.0.5-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ceb67ee7bcbbeda8f9ac67c769577cb5e945b3083ef3db4a47f84720a23a5515 |
|
MD5 | 7c30ea69ce2264f36b635238f5bd93a7 |
|
BLAKE2b-256 | 61af74d34210d2b56e73b93613c6abc76ca0b958cf3a3a4ade32396a94d0ca79 |
Close
Hashes for concave_hull-0.0.5-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b024a4df9c982c4f5c582baec16b056361de3a92871b30e64ada7c6fd1ae4f28 |
|
MD5 | af8d6164c60f9a2c6a675d0181861539 |
|
BLAKE2b-256 | cfc3006694f85f5d364d34e1f9fdd23260e98971dac0f12eea66b50a8ea557d5 |