I wonder if there are any numpy based tools that can:
- given a binary input numpy image in 3D, find its convex hull;
- and return a list of indices or similar of the voxels (3D pixels) that are within this 3D convex hull.
One possibility is to use skimage.morphology.convex_hull_image()
, but this only supports 2D images, so then i have to call this function slice by slice (in the z-axis), which is slow. [Edit: See note below.]
I definitely prefer to a more efficient way. For example, scipy.spatial.ConvexHull() could take a list of points in N-dimensional space, and return a convex hull object which seems not support finding its convex hull image/volume.
points = np.transpose(np.where(image))
hull = scipy.spatial.ConvexHull(points)
# but now wonder an efficient way of finding the list of 3D voxels that are inside this convex hull
Any ideas how? Please note efficiency is important to my application. Thanks!
Update: In the meantime, convex_hull_image()
has been extended to support ND images, but it is quite slow for moderately sized data. The accepted answer below is much faster.