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.4.tar.gz
(2.9 MB
view hashes)
Built Distributions
Close
Hashes for concave_hull-0.0.4-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdfb757a18ed3ecea2e687bce549a2219622dc1cbdf1a651d32d81abf9eadfe2 |
|
MD5 | 31aefb94032b13587bd0968097e0c889 |
|
BLAKE2b-256 | a269aae9b12ec6907e6baaadd152d3548f200daa2a9d5eed841af61bce79a886 |
Close
Hashes for concave_hull-0.0.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9d7261ef0c35f611ee33b980248afbc9752eea1b508dc0e432fa93cbaafe38b |
|
MD5 | 30502688da8df229b4783e689fdab51a |
|
BLAKE2b-256 | 0b5b5b24dc58ee10f6b631d39d6b8b97a5b699618de85822e868fc33b88f9ac6 |
Close
Hashes for concave_hull-0.0.4-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41650d21a36f74874843edc9152c97c820c5b3d3abdd22551233ba0b6a19b0a2 |
|
MD5 | 357023f7501d63bf29e18f06ad4b35a6 |
|
BLAKE2b-256 | 087bfb420baf49d42ae9abe982153d4d8898cde3afa052aec2182b5826dfeb58 |
Close
Hashes for concave_hull-0.0.4-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4a69e6c787d9c2ec69a9865367824a12d667da8cf47c83b59b3c0168cef6fbe |
|
MD5 | 2fdd52a5bcc2a48f84e1e83d7c5311e0 |
|
BLAKE2b-256 | 4b4ed04e93596db02009e3d0e81dd2f89343f2057c50278ee24bfa4b112fb844 |
Close
Hashes for concave_hull-0.0.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7acd57af724395b6cdd02572e737eeeaf5a5b9954e57e20361b246f663ed2886 |
|
MD5 | a7a0fa55973c707a067d2945ed4b71bd |
|
BLAKE2b-256 | 90ee249efd60d30387e0e6fd6c8510f8b0638b51e8b9ebea28e8f21cbf5f5c87 |
Close
Hashes for concave_hull-0.0.4-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4d8fe2f761978ff48d6cbbe090b84f13ec38301742a369660a1b25392a052a7 |
|
MD5 | 756a35d06ad7eeec170313e3854a0c39 |
|
BLAKE2b-256 | be45e4430edb46de81dc2450ba9d0a17724ec65ed4ed6f80fe48bb9cbc18c130 |
Close
Hashes for concave_hull-0.0.4-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 811dbcc2be08971ad0d6e03195bf02564cf90a5c53bfee6aec45d40be041fa73 |
|
MD5 | 1276bebf50c6569b1912c32f82cfea7b |
|
BLAKE2b-256 | aaf56ca017f4cfc2fcc1fcb053da25fe37f12687a0eb3a4a38d6e1a7881c30b5 |
Close
Hashes for concave_hull-0.0.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b13c20fea453e74eaa329d7ef2a7928839882bc032842932ed3ab5bbc79b8bf7 |
|
MD5 | 7cec793526e098a695f159c2ccdd1686 |
|
BLAKE2b-256 | a52ae6ae5e1bbfe129db298eab463ee53652bb066f5fd3486474c2dc6a39e05a |
Close
Hashes for concave_hull-0.0.4-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11e7728af1678f802f4ea8e0b02756348ad81e87cf2b226520a2cad4f1aa42cf |
|
MD5 | 8a33ff0203fe7eef1f0ee66585770573 |
|
BLAKE2b-256 | 4cc138927f2b87f400e378b623beff7af6552c89a45f5ee79983ab3269fcf8d1 |
Close
Hashes for concave_hull-0.0.4-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c5d68fc010e577f22fde0456758747e24b352dad7c9eacb2c9eb198950aed98 |
|
MD5 | 315a5ffc66ba7234845f0efb11d2e549 |
|
BLAKE2b-256 | 83e8d06edd699edaf9e57bedfd398175a9d7d95a785cb4a6e68418866cb242be |
Close
Hashes for concave_hull-0.0.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8bab824c41dfb107635cffd36f89db486ae7c18d77b113cacb0b71924bf44b1 |
|
MD5 | 6d21cb535f4d19e15302b2c7eea841f5 |
|
BLAKE2b-256 | 8a8a91a4d34218355535538df28f494968fa0d60cd57febad03db52a7d7d68d4 |
Close
Hashes for concave_hull-0.0.4-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5e32366ec46de50d07876e075d7762df626b881dd139b47b0a5f7baf5578c31 |
|
MD5 | e182b01b93dae3f6e9227caeb1060663 |
|
BLAKE2b-256 | 73542097853a73eca2f0f413ab3c593bc0c85f348ab76e533854e616e61b8367 |
Close
Hashes for concave_hull-0.0.4-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f86b016c0d5348cb3eb5fd891badcda98e8e12e196546ae74f73036bb10009b3 |
|
MD5 | 9adef03c1206eb46c0a66368823517f8 |
|
BLAKE2b-256 | 255e1a25367eaa62fe2cae657187061c1e3ffd64f4d1559914022801b6b00331 |
Close
Hashes for concave_hull-0.0.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72ee4692e37e0d4de55b78baab9208d589a6cc17ac43c9cf122882354030ebb6 |
|
MD5 | 3d63316023b85ab452fd5a72608accfe |
|
BLAKE2b-256 | b2cd58fd33a4b5b3ce25da352da6029146693de7403f99bb99988ea923cbd825 |
Close
Hashes for concave_hull-0.0.4-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c55f299d3e07af24704802f33004f8c86d4d3bd906810d1a51ab3e911a4773b |
|
MD5 | 6b092a3246c582f7c3400cf11f6eb133 |
|
BLAKE2b-256 | e2dac55c139e7cbac189f699b2027221c09c98d118099c08d5e2587eda32c1df |
Close
Hashes for concave_hull-0.0.4-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90bcfa128d043928d6123c243f44441d38bfee7176dbd2f7bc6bb56fc6656099 |
|
MD5 | 1786943a8440acf3fc6eafbc80c5027f |
|
BLAKE2b-256 | b87c8ee33de9116c2719f4545bd3a1480998182b3aef7236af510894569b017c |
Close
Hashes for concave_hull-0.0.4-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a375cb9b4cdf2b0d83555f6053bc03bf4ded7af46cffdc3d4575fa0a878d631 |
|
MD5 | aa253eb1489773e7873445ab5aee0d45 |
|
BLAKE2b-256 | aa446ff15a2b1c4df6c5c86a2487dfb5798f5326bfef96badaaf8e04747451b4 |
Close
Hashes for concave_hull-0.0.4-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad73928c18811ceb9967bf6287f63d570a42d9d580fd4604914f9f9bb8447ccf |
|
MD5 | 95d6f7a4625140a535d65b843c64a449 |
|
BLAKE2b-256 | 1b059466cced13d83ead494291972d8b790d647a80e9d868f60a5de810902ead |