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.8.tar.gz
(11.4 MB
view hashes)
Built Distributions
Close
Hashes for concave_hull-0.0.8-cp313-cp313-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bae56db77b46ce6af120f321857e432e5695715cbd14ae919b50c3eace0d63ea |
|
MD5 | 76b11b493739d015f8427a680dbccde2 |
|
BLAKE2b-256 | f3172f324af45f36617af03a6cb92863b787bfb4ab1a69509bd13e758be076c0 |
Close
Hashes for concave_hull-0.0.8-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf6a0bb9844df552e8b511a245f0bb2b56c219a328952fd154a126a8c633c36b |
|
MD5 | e42651018805d6a2657591ab14caeae4 |
|
BLAKE2b-256 | f1c690394575ae6ee645a779073678a716fbfa5486178b00c677b1d4c3eacb55 |
Close
Hashes for concave_hull-0.0.8-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5738e5947c921f0087e9b0ec9144ee1c86de02cf88a96d90f659896e4e15c36c |
|
MD5 | 30d36d512aa42c6f26d28007d50925c7 |
|
BLAKE2b-256 | 23022b70897c9a3bd8f2497ce9d2d8698a7b6bf5e767ab342cc99f10a380b608 |
Close
Hashes for concave_hull-0.0.8-cp313-cp313-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a75a68a82c6ac9b2e39d74f5d665e9d8cee19a91c3f5d79b0653a3e6c7bcba95 |
|
MD5 | 6d9af8451b222592a80fee3e5b76fecf |
|
BLAKE2b-256 | d6147852b414a07f8bd523344aa0742e91885923b12599b8bd59945249b5c77f |
Close
Hashes for concave_hull-0.0.8-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77e737da20715a30dbbc39713ff607599e7476907ed16d8565517e2154673f6c |
|
MD5 | 8e6a9641b50cfc1504b01be9edfa6b33 |
|
BLAKE2b-256 | 2b4c940d27f20dd032399420cce293a243a684b95c30d345d040ec839d547ad3 |
Close
Hashes for concave_hull-0.0.8-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2f5c0dc29ba18ba08ed113cc0e45f23463c238e88f6928cd124c93cb4ba9dfa |
|
MD5 | 812fd55c8a8384651775902805eda08f |
|
BLAKE2b-256 | 6233e5ef82a17287bdcfb3b7ef1e18c7adc265902a220f2a183dcf3b5fccdeab |
Close
Hashes for concave_hull-0.0.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7ac9950d7f8460b3a48dc3ffe4275329263e6a514cdf7d4ec35f5d94149f22b |
|
MD5 | 7c90abf04f4dac2711be35feb2fd55b4 |
|
BLAKE2b-256 | 47f3b3f95a2b453083c1b3ae2934a8f8f3ea46d2fcbdb345533504d545a8476d |
Close
Hashes for concave_hull-0.0.8-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60fec8c40d63130afb458525d9e8f32353fb286e0c5dec137ef44bb0fd04a0e3 |
|
MD5 | 890ae55ada144c8e225027adb30add00 |
|
BLAKE2b-256 | 9d841f9e6a59ce9c460b89b90010a014a9475804b581aea0083b8bd858630098 |
Close
Hashes for concave_hull-0.0.8-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af67e9a2cf5303d5d7898c2d6ae23b1c191d36e017c9e81e0f4c21ed2a94f791 |
|
MD5 | e520fb012b60b60f1afc6266e49e2d62 |
|
BLAKE2b-256 | 72083e055334961f0648c80ece1e1e7ddc76313f4978faa5441edac30258171f |
Close
Hashes for concave_hull-0.0.8-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99c412f2e6e41c9a24505ae4f252a894cfcaafdb5e81b73a78df284a60789fc6 |
|
MD5 | 35c8d9724bd1bfa7c160bb54145097f9 |
|
BLAKE2b-256 | fce59f35843c5a0ae042a85e2526b85edd87e66e95022e86a3052b2e095e0ec6 |
Close
Hashes for concave_hull-0.0.8-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6779a2ae9dff38ce2d73217b6cacd02ed29d417a8a2372e8b0f74a1849158aaa |
|
MD5 | 01fc9de95f2d3b14d4b07c360330b66c |
|
BLAKE2b-256 | 1a07ae0b82444011e1a841d4751755bf93db0a59a0bc0e5e47d959eedaef87a4 |
Close
Hashes for concave_hull-0.0.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6a8eaf7e642b5eea23ba2408d9eb9add65645f28b78e4ab8c7486e8ced99218 |
|
MD5 | 2dc050f5b1d7637d11602811cdc842dd |
|
BLAKE2b-256 | 77d56ea06258aa532a5d5f1f0184c4fd58923305a6ee1e136da01c0c61e97717 |
Close
Hashes for concave_hull-0.0.8-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74e668cbe237eac3e409628bcc51d259184e8b5186288794d2a8f21633b35e81 |
|
MD5 | 3822c1535c8ce3c7b5fd15471c425982 |
|
BLAKE2b-256 | e9c7ed8f81299cf1cd105e3ae453e3e64148bfa789582f14c1c51fd86805cc98 |
Close
Hashes for concave_hull-0.0.8-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69521ecd034397b6a187d9b7893072bab97ff7f807c03fdbdbad45faabf5f530 |
|
MD5 | fdb51a675f6df27c5b9c4ba9919c400b |
|
BLAKE2b-256 | 64119f72b1740b776b52112d2c63e568c45b59d7d3f06c610b3b62083c014211 |
Close
Hashes for concave_hull-0.0.8-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccae3d33471c2cae0ae2de7291989484910f4e6f74be327aabef89937e4d8792 |
|
MD5 | a9cc73c5a6b44e48738149945b7283be |
|
BLAKE2b-256 | 91efaf8d8cc45a313fbbc1be13cf87e941516b131e1dbaff9a29ee3d3c4cc2f0 |
Close
Hashes for concave_hull-0.0.8-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a32809238f59b2d709fb18e4e0ad8b51eca7c7aab908f676758d6e9815985c69 |
|
MD5 | 1f998c027d778a582005ea85217f630d |
|
BLAKE2b-256 | 84d32396aed17f15d90abba81aa638b224b02307ce11a17b59d3c328e5002aa5 |
Close
Hashes for concave_hull-0.0.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c93b3d3f32f68f5c407dbb74a61213c699316f29108d21291c42f29bcd78dcb |
|
MD5 | 9505c0f5a706634fcdbdcfdb5e055b61 |
|
BLAKE2b-256 | 49906ef88456e7fd420c56ecda92e4d079b0975ba27658cd57e3b539a176d5c0 |
Close
Hashes for concave_hull-0.0.8-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 270b06a197551e992951f474a34081dd0b6da0a142e45f2488393c0ceb7259d5 |
|
MD5 | 059c8f5e8d67fd3dd5b290983c14d3f1 |
|
BLAKE2b-256 | 91b652e820c2f80131087ddb6911e0cab54c4d90e6521fa27107af313376c4b0 |
Close
Hashes for concave_hull-0.0.8-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3315ab6ab2e4c979f17a8cde9f50cdea899911f5510e07038ed39e1624c13555 |
|
MD5 | 4b2a9fbc7cfd394f3bd60bdd7986ab17 |
|
BLAKE2b-256 | a21eb7b352da1ead063f043a7ebfb7e2531a6b3437cbd5b98f79948e635d9a0c |
Close
Hashes for concave_hull-0.0.8-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35ff18ba14073992f16c6892c208b136e88603cde9fcc3342211c2c61f7540c2 |
|
MD5 | 97b8b81355695e3a59333010ca7801db |
|
BLAKE2b-256 | 9beeeb710c979f7382644e65d2732574f80f22cb0cc7bf45bf221b381b830e35 |
Close
Hashes for concave_hull-0.0.8-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a912802619e39aca31cdc9f84f7b8574f3a1ce2478285e7a467e1b5a34f757d |
|
MD5 | ea30ba1cf4cd134c5803a8c261e51c79 |
|
BLAKE2b-256 | e6da74e77531b4c2ab71e4efd49719c157e1b49587060cb573ea6698b7fd490d |
Close
Hashes for concave_hull-0.0.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 442022518dcae675515a657c861e968945857699f226ec4212bf96afd7666da1 |
|
MD5 | 04878949d2b5f8a65e7b25fa3a6acba5 |
|
BLAKE2b-256 | 06868066a5754f7468f0a3b1f29bfc9ea6a140c27416b9cf54a30922b13991cc |
Close
Hashes for concave_hull-0.0.8-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 046ed62d02191fa569a69bdb8be977b81f617894272d9b708e9b19d4728f18e2 |
|
MD5 | 8b869832158ff0ef20282fbbc8f2b326 |
|
BLAKE2b-256 | 0b090f56a9b54d927b364a26febcf3fc3d2fc243cc3a68c48ff29d15bfb95e72 |
Close
Hashes for concave_hull-0.0.8-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6af7adaf9736e7d3429e1cd9176df0d43a339ed49491d10a1b28f887ce5a060c |
|
MD5 | 617dd0e84e0595106d063c48693913b3 |
|
BLAKE2b-256 | f7082a343c6cd50af755124205f8ccf3eca59d55a14215a58729e933a5c73ed4 |
Close
Hashes for concave_hull-0.0.8-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20524dab44d0a4b60e85b03dc1165f8d593b17d6a49f835f6af7df26df5d75c8 |
|
MD5 | 6810605126234c53aa252923c7891056 |
|
BLAKE2b-256 | 8c2d531ab297bc092ad07cff391459ec1329459c6689534ab86a74443dd83ac4 |
Close
Hashes for concave_hull-0.0.8-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62b0f998c52480c4ee7310a4d0422b320997346669c5885d50b4ad2115a02b48 |
|
MD5 | 5ce462efdd7144c6c48415514e66100f |
|
BLAKE2b-256 | 6c337d4857f58b11f039cfa537f41e65ba7aa2a1b95f574bce991235615a71a1 |
Close
Hashes for concave_hull-0.0.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ff636765583af9b5269abddc8b06477d5d3ee041a4b158a8aba7c2eeeba91a6 |
|
MD5 | 875d4cf753060d68e984786b007ae437 |
|
BLAKE2b-256 | cc70d6cce2ac4e0e55eaf4a55b4ed7bec9e6b17fe4f4e233120704390d68cb29 |
Close
Hashes for concave_hull-0.0.8-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b29de674790ffd11e6d61381271f25fff996d4bc1e8138c97e92af208708df0d |
|
MD5 | 4218e59f3b385a090a321ee1c4df7a79 |
|
BLAKE2b-256 | 76d1fd2c244394ad67d03d951badf1e4a82df9792e87f655603caed6b742e6ec |
Close
Hashes for concave_hull-0.0.8-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c559098f07703bf305f5e4a8499ecb5ef5c51dbf76cbea3a3c7f2360bf55db0 |
|
MD5 | 347d2f235b0b1b454bae5049186d9d27 |
|
BLAKE2b-256 | 7bd0f937b3f4527ce4969d9cef16749926e2f626db844ac84455d0a474a081be |
Close
Hashes for concave_hull-0.0.8-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 122bc39c1acba72766753c8a7c2c969206cba2ee1216c1d2b04a14d1076ff244 |
|
MD5 | e561ee4bd727caffd3d62d974533a44a |
|
BLAKE2b-256 | 9e1ff04bae148d738a3cdda62ef11e134502ab4511fee079b0e1962a015ba291 |
Close
Hashes for concave_hull-0.0.8-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | afe343a6d99755b72e5b7a1a6dda03a467c4aecc259306a74978a03c100e4298 |
|
MD5 | 453e5674240e0dcb7e2c1929379bea09 |
|
BLAKE2b-256 | c22e7f712218efdf255a22759b2511fcb9eff4c1141afe712db077fbdd7aa1fb |
Close
Hashes for concave_hull-0.0.8-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9864de39f8aa603082033d3dcca8678ffc1ae0f519ebd48523fa1c6e93042f3 |
|
MD5 | 6da951623097ebd087fa95a361226fbd |
|
BLAKE2b-256 | 7a98531006ca4523a35cc78fa064a87dbbe99fac4b25550fe09f1d14d78c0b49 |
Close
Hashes for concave_hull-0.0.8-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88467ce9ced33caa3abcfb73080ed654a51410994426c38bf656e6d2ce35e9ac |
|
MD5 | 14b6d9cc4bd25227bded334ffc2f277f |
|
BLAKE2b-256 | a85726eaf74da980f8e77ce189d8aadd84115c4dad3a6154832c877058f0aa48 |
Close
Hashes for concave_hull-0.0.8-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a429ff6e32fa80cd434477f16d31fa6fb0d4ae10d6c2c69f09b37abd22bcffd |
|
MD5 | 66661b26573b52e991f0e3137b7a92bf |
|
BLAKE2b-256 | 3dcdc03c7bc627c5c6b38956c35a284c6db8234d7286f4cbe40ef9cf0e00c76a |