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.7.tar.gz
(3.2 MB
view hashes)
Built Distributions
Close
Hashes for concave_hull-0.0.7-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef356d4cff7c911f87beb05a537dfaf4ceeaa925ba038ec6b47f0845272ba520 |
|
MD5 | 11bb50ab235dc41907b5cf5a17cad682 |
|
BLAKE2b-256 | 8d263b6e5ab91229bada1b805c52c75b01c9c37cf230d0f5e69081a0469bd59b |
Close
Hashes for concave_hull-0.0.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cf8ad57d3d1b5cc17c7dbe8a2adb7e73649851046589a5499a239c91e15ccd6 |
|
MD5 | ceae514fb0b12812d45df0c3f0da8e80 |
|
BLAKE2b-256 | 99c1082d2b6abf37840c76be85ec1fe166d55dc3d642bd8b4cb7dce460adf5da |
Close
Hashes for concave_hull-0.0.7-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ba921b90ad5faeb72b019030d46627c79afedbf53786444163b6dc10816c972 |
|
MD5 | d03840b4cfe06c948a4e438fad153924 |
|
BLAKE2b-256 | 017a733310c7e40bd5a9d45206608e72006558d0cb63d60fee3413efd1a18b5a |
Close
Hashes for concave_hull-0.0.7-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1a3fd0c839b05213943d97ffa243d2b4c827305a5ceda1a3bd07b8e1bdd95d5 |
|
MD5 | 105b3974825d4865e968602b5d2cfb48 |
|
BLAKE2b-256 | ef1a9cfd6611268e35979f06443ad3a994a12cf9532d37c49a675d7567a92196 |
Close
Hashes for concave_hull-0.0.7-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2419cc22b43e137781b018e956dc30be63cb044a95b80c4156083bd094e7ca34 |
|
MD5 | ff1bb154aeb00721172713d432bee4b1 |
|
BLAKE2b-256 | 550cbe8abc20bd34423635dbeba7dd03eee46d60cd0c18fcb753d2222e6fc938 |
Close
Hashes for concave_hull-0.0.7-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 858ae52b18fa966d662fca056be1fb15b6f3ef2fbd47558fd700e63bf18793d7 |
|
MD5 | 684032b8b97608b540fea4ea64a922f8 |
|
BLAKE2b-256 | 65809ed5542f47817e5f15e9531c0bc73148e319b1b3cb6a881daa8e67e33983 |
Close
Hashes for concave_hull-0.0.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08a16f4838d5ed49b5479a231390945965fc485c66ff706a17b075ffc4945380 |
|
MD5 | 971872b1ae296672431afb8edad9b7bd |
|
BLAKE2b-256 | 5c20f42ad6a903d58c2af062b9f94d8feff18ceb5cfee3de8e65237569c1e2fb |
Close
Hashes for concave_hull-0.0.7-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b33bae1b11743693ba1d3017a163eb5c88996048bede4a3a154795d12a027759 |
|
MD5 | 6cd6c748d81e96c7bf021f141a43a7b6 |
|
BLAKE2b-256 | 5041ff46025208eae48a24fb5313e6e431708114442f5f03f60e720be1ea5b53 |
Close
Hashes for concave_hull-0.0.7-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0cf87ca54d6117b188d34ef1a5ca624c4b263ec2636fc0a59b1705ddbe8e83e |
|
MD5 | 35c7f72f6b8d530ca55444539e5191a4 |
|
BLAKE2b-256 | eadbb2d198876a764bc80fda0a0930a216698f800d4a38e9d795198f6adfce4a |
Close
Hashes for concave_hull-0.0.7-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7127e5cdf50d2c7b54b09960f44b04df7bcdf68f484d9003c203a30a4dbb9d66 |
|
MD5 | 97aec54d2cb739f9df280a6ae2a17ff0 |
|
BLAKE2b-256 | 168630453626051cd7abd1efab35d01532155cff74c05b81ae4429250b070f38 |
Close
Hashes for concave_hull-0.0.7-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31cdc14d42d17fe4dd9dd68825e01aadfbb50aa20cdadd802a4b97fcc3e7cb73 |
|
MD5 | 18bcf84851714cae75008cdd09f86e41 |
|
BLAKE2b-256 | 42f5a3f0557ae5ed49126676d70caada852914f8eb6de2b54e526820738d3048 |
Close
Hashes for concave_hull-0.0.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8a5c305b36f2a4e74ff5b2a49372ac4984da467ae0153cc94002dedb01c40e4 |
|
MD5 | 53054cdb2157d42007841e89d8991237 |
|
BLAKE2b-256 | 00e308a821213db92257ca0865da3db3443022d5a7073116c38124233749389b |
Close
Hashes for concave_hull-0.0.7-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a57781476f83086244d6934e067516f556cc60fccd2a495d4bf3ecbf5dd67228 |
|
MD5 | 0815bd896f5fd6131eaf6fa238a083bd |
|
BLAKE2b-256 | 7aaed90c9cbff097ee4f7f4d326f45ae4e329ca4fff996c5d829a1277a22069f |
Close
Hashes for concave_hull-0.0.7-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6e2e26c4c61c7a8cf9c21781603e281f36cd4ad0c4fc3685197bcd97a554484 |
|
MD5 | 3adb12006a365fa311030439999244d7 |
|
BLAKE2b-256 | f36f7139cd6b0b564c4539e7634645debd932b6285c4b267d00fee771edcfc42 |
Close
Hashes for concave_hull-0.0.7-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00e4a3e1a878093d492f761e7cb2aa32b7e3c4663eab80bcc0ddf5608ea8a179 |
|
MD5 | a5a135743102d8543b6c69a703406a53 |
|
BLAKE2b-256 | 3f6e8a9d21fef9885be601478d5fc44e7b1c0dc3e7a913d0f3a34212370f015e |
Close
Hashes for concave_hull-0.0.7-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b9e61abbc8c31c783b4c12cceb6b87dd35033adca9e8122b250d07740948996 |
|
MD5 | ad26fb920f73a74e7645e22836e1c0ba |
|
BLAKE2b-256 | 2acb45cb5fd4c42c4e6ad3e27d687c55aa0d0adfbd8c6605957e0a6cdfe3122e |
Close
Hashes for concave_hull-0.0.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0bca6467a733be6866c037536eb6df194717de6c3888ae5b59c6b744b97cf7f |
|
MD5 | 788dd73fb314fc409025926ae9fc3caa |
|
BLAKE2b-256 | b3590b85f2bc940f386976c395fbb4f5dfa994aba38c86e84fa11b181a6d783d |
Close
Hashes for concave_hull-0.0.7-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b92c359ccda8eed6a02af96c8f44597a8ff68e13dc05e885fdd246ada508fc8 |
|
MD5 | 0593557a5c9241c7b7a776259b8f0179 |
|
BLAKE2b-256 | 77c77061622e6ebf6f20d25dbf57dba6557332d8b1e8e3618cabfa25d0d8ad1d |
Close
Hashes for concave_hull-0.0.7-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8a719e11b0475a4a3b02d09a06688e8c19fec56b061b7f288986f0dc2de485b |
|
MD5 | 546f9f3dc63e890e5f5c6567cf10b810 |
|
BLAKE2b-256 | 6727c4e6a02a9b647ffe348e90f4a5690bcbf8422ef59400c95180d9a8062d7f |
Close
Hashes for concave_hull-0.0.7-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70bbe1f75bc4ef2e3c7305fa7aebba40a8e005e1d9325a51dd46d894f8b81024 |
|
MD5 | e29fb6929a2f7f634b257334008611d3 |
|
BLAKE2b-256 | fa88b09ef27a2d8d089b3c452a8ec9a73283b53bd6a4d665ca6d3553fe9d222d |
Close
Hashes for concave_hull-0.0.7-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd8ced0ea49597cab9c3fc5f5e9eebf074b71d63b951b9d8dcd7dbec791f83ea |
|
MD5 | 42ebf81f79526ff0403ae29f413cf8ab |
|
BLAKE2b-256 | 3d84709dc15174b12d2a3176114c5aa807fd37373db83b2985f31dbb9e2523f5 |
Close
Hashes for concave_hull-0.0.7-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b5644e8c980ee2854063d824edf7b98b1598d1c4c919f6aefba517d1dbe28e0 |
|
MD5 | a7f764a85cd6a4994e8f6221ed390d5e |
|
BLAKE2b-256 | bc8a610b132f8cce7ab69cca2522b7de48bac7e598b73b94eef4820246c74611 |
Close
Hashes for concave_hull-0.0.7-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8754fca3cd9e930b87268afac41f0638c81dab1d9fa971a3bc95def4502ba3ff |
|
MD5 | bd341c3ce627d00cd3a625ab098f3575 |
|
BLAKE2b-256 | 911c360513b3c18907e43fa23719a1ede55bc39ff6810536cfb51fafff837356 |
Close
Hashes for concave_hull-0.0.7-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | daa6b0934916748aa87fc9ca63ef16f39a9cc63d81106062cb12293d46218f6c |
|
MD5 | c2ef15142814c5f00001acfb5c9b012d |
|
BLAKE2b-256 | 3b133d9b467f284c16bd2d3dba1eab0574454e4436f700556233f9f2d45eaff5 |
Close
Hashes for concave_hull-0.0.7-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97620d9c4e0ceb9af8127433701ff3bdb4843cdb66d34c3c30fbd999d27ae80a |
|
MD5 | 32e1610b5cbca8115a59e69d17ce629e |
|
BLAKE2b-256 | 33e75a6c93cbfacbbe1a8e3268a7e5c09331b2f408f9d20278fbe561da0aa281 |
Close
Hashes for concave_hull-0.0.7-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7475a2f4275d4c4c62e4ea3d0862c31c47c1a41f8106dacc5440a3a839d324d |
|
MD5 | 45a2710f90a8246936137f65ca84af77 |
|
BLAKE2b-256 | 60444035d9544a8bdcb6b31d6960716300c5e565ed6ee3e4b987dda817776d6e |
Close
Hashes for concave_hull-0.0.7-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 394c8c293955684e57cb898f8a7e9cef5c9bffc13760cea1d1753ca4e93c3b85 |
|
MD5 | 91196ddcdb8cde66ef71024d188d7025 |
|
BLAKE2b-256 | d656afcdf7e855cf39aab1a3462c0ea172f5e920fe5bd22343ab0a24213ee04f |
Close
Hashes for concave_hull-0.0.7-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9367640b189f68a81aff34a53d5f7131eca3983895527e3ffda37100b454ca95 |
|
MD5 | 79fe0168ae99e222315f646044d0f4e5 |
|
BLAKE2b-256 | de79e4bcdf70850da00ec4a85b3170ddf60f0a42738df51def8634780fb9c02b |