This repository contains a C++ header-only implementation and Python wrapper of marker-based 3D point cloud segmentation, directly based on the following papers:
-
Random Walks for Image Segmentation [unpaywall]
Grady, L.
IEEE Transactions on Pattern Analysis and Machine Intelligence, 28(11), 1768–1783, 2006. -
Rapid and effective segmentation of 3D models using random walks [unpaywall]
Lai, Yu-Kun; Hu, Shi-Min; Martin, Ralph R.; Rosin, Paul L.
Computer Aided Geometric Design, 26(6), 665–679, 2009.
To build the docker container
git clone --recursive https://github.com/kasparas-k/random-walker-seg-pointcloud.git
cd random-walker-seg-pointcloud
make build-dockerTo run the docker container (in an interactive way)
make run-docker
To stop and clean up the container
make clean-docker
This package's C++ dependencies are: Eigen3, OpenMP and pybind11. They can be installed via conda:
conda install -c conda-forge eigen libgomp pybind11The Python package can then be installed locally:
git clone --recursive https://github.com/kasparas-k/random-walker-seg-pointcloud.git
cd random-walker-seg-pointcloud
pip install -e python/Or directly from github:
pip install "git+https://github.com/kasparas-k/random-walker-seg-pointcloud.git#subdirectory=python"The segmentation markers need to be user-provided, so this algorithm needs to be part of a GUI point cloud processing app's backend, or to consume automatically generated markers from another algorithm.
from pc_rwalker import random_walker_segmentation
# assume an xyz point cloud and markers, a list of point index lists, are available
# by default, (n,) shape numpy array will be returned, where each element is each point's segment id
pointwise_segment_ids = random_walker_segmentation(
xyz, markers, n_neighbors=15, return_flat=True
)
# alternatively, a list of point index lists can be returned,
# corresponding to the indices assigned to each initial marker list
segment_list = random_walker_segmentation(
xyz, markers, n_neighbors=15, return_flat=False
)An example of segmenting a bunny point cloud is provided in examples/segment_bunny.py with an additional dependency on laspy. This code will generate a new point cloud you can inspect in a software of your choice, such as CloudCompare.
python examples/segment_bunny.py