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.3.tar.gz
(2.9 MB
view hashes)
Built Distributions
Close
Hashes for concave_hull-0.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52566995f3eb70986eb4ac0b174404120a07482dd33a1411bb01e6864c4f485f |
|
MD5 | 2f73e3cec0297952adf2551a456eb205 |
|
BLAKE2b-256 | 757fde6757ae3a236676fd48b6f88272dd334c8cd45345f511cfb6f3a673c4dc |
Close
Hashes for concave_hull-0.0.3-cp310-cp310-macosx_12_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fdb6d58d849605386941d3e4de607a9ed9dfb5b31bd9a8c9a3a93ddfd9010df |
|
MD5 | a9f69d8c302c4133ae2e947e62eae157 |
|
BLAKE2b-256 | 199b0d7b91462866a785306b1174b6c2447c69782cbd27ae48cbc87a246998ca |
Close
Hashes for concave_hull-0.0.3-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e691ffd1fba1f4071ae8ec1b9bed0f635aecf76b48da417d9798f93327b7992 |
|
MD5 | 1ddc943724f6313a5788dcd00b3f38a4 |
|
BLAKE2b-256 | 23277f3f9ad38d6124cd0b7b274d1bf77a37b61826c229469d4f5364fe0bd041 |
Close
Hashes for concave_hull-0.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7726ec1ec87f594565c4e46d875808ad077c056ff800b2f3cda6676387c91465 |
|
MD5 | 9cc3725dc0e61f494b27044a1fb66ea8 |
|
BLAKE2b-256 | 41b3354300e78329edb393d9bc4797ab2e27d1e01a066ae6b9b1e380d1472976 |
Close
Hashes for concave_hull-0.0.3-cp39-cp39-macosx_12_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7911c9c481614ada44195c08002bfeb9ef6a2ce9b944855a6b6f5f730b7ab0b6 |
|
MD5 | 7d1161bb53ab78f22e4748e851e4d2b8 |
|
BLAKE2b-256 | 62b06355af02e33a66b36a4f1091b082cd81906393b78d1ed912108694b52b57 |
Close
Hashes for concave_hull-0.0.3-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 897dda7ccbb8acb2d10d5f3c36197f78bb523d4128a258ae7abb5df3d691f17b |
|
MD5 | d2bec6bb15291fc6ae1ad51932e59ec6 |
|
BLAKE2b-256 | 203cb5ac64b2d9f2a0e94e3f6a35f2ad2bda4696826a48376053372cefd9207b |
Close
Hashes for concave_hull-0.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1d20090af5b933eae4db800bb7df5156b14cc626e980de58a9fc71b68e626a9 |
|
MD5 | 500fb7ba315ef2ae746ab3b01ff30ab7 |
|
BLAKE2b-256 | ea8b26837f67b844fc0d68678a0b66c31a77ee2937c8eac3b91c86629017c5b1 |
Close
Hashes for concave_hull-0.0.3-cp38-cp38-macosx_12_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c83ed5f06bf9ec73477a9c945c91fada92149ad18bba8ffaef8c93a46f76956b |
|
MD5 | 69f421eb338d4445dc1cc7c5395665b8 |
|
BLAKE2b-256 | 6984016e3528226b0fe3f472b0f80d35cd5fc8e892814cc083cd17f1c64cf434 |
Close
Hashes for concave_hull-0.0.3-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36ac62dd5b9609706f0b081149688c61379ab96f2cfd9df4e3130044d56cc729 |
|
MD5 | f50f0a52a597f7d9c34fc117ae8a3886 |
|
BLAKE2b-256 | e34a1fe6e51fec83044c39a47ee26b845b78aab967689db4e8aacf56cd6cc88e |
Close
Hashes for concave_hull-0.0.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1c34726ee2c3df5587e7f202ad844dc1a8cfd8d463cd04aa1dc6e40a9e78d92 |
|
MD5 | 9a8302d056afeccc0dd03e66d59249a9 |
|
BLAKE2b-256 | 22e0f58dfa66914c7614a21ec7c2a0ce7651506de4c83d837d7629febfc0059f |
Close
Hashes for concave_hull-0.0.3-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75eda771a8c8a1766ded55064853db45fac534e006adb0bb54761764fdd675af |
|
MD5 | a4825150d782d0e1a8248f10d16e02a2 |
|
BLAKE2b-256 | b764d892249ec0d6e91144cafb3ec1c612bbf3677ea62b9d66049e09b453f97d |
Close
Hashes for concave_hull-0.0.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0024e5fa7a09c94488beb984c0eb3aae692887dc54d7bac264785ba3d451670e |
|
MD5 | b172d70f0c07f5bfb4eb1491d0dc9397 |
|
BLAKE2b-256 | b89272a15f30cabbbfa6c77fc931513bcd1612777372837399b9c3b903c6b35b |
Close
Hashes for concave_hull-0.0.3-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6f77a9040d22793c531ea7969f0060568a9f78e099f1b5bd535c7723432a0a9 |
|
MD5 | 0e6ef296f9ea0562c78f60d1cbb652df |
|
BLAKE2b-256 | 5fd0e19b16d066252e8e8657168e526f66defa9d08018c936477bc1f6bb2b626 |