Skip to main content
logo

segment-lidar

License Geomatics Unit of ULiege - Development read - documentation

logo

Python package for segmenting aerial LiDAR data using Segment-Anything Model (SAM) from Meta AI.

This package is specifically designed for unsupervised instance segmentation of LiDAR data. It brings together the power of the Segment-Anything Model (SAM) developed by Meta Research and the segment-geospatial package from Open Geospatial Solutions to automatize instance segmentation of 3D point cloud data.

results

Installation

We recommand using Python>=3.9. First, you need to install PyTorch. Please follow the instructions here.

Then, you can easily install segment-lidar from PyPI:

pip install segment-lidar

Or, you can install it from source by running the following commands:

git clone https://github.com/Yarroudh/segment-lidar
cd segment-lidar
python setup.py install

Please, note that the actual version is always under tests. If you find any issues or bugs, please report them in issues section. The second version should implement more advanced features and fonctionalities.

Documentation

If you are using segment-lidar, we highly recommend that you take the time to read the documentation. The documentation is an essential resource that will help you understand the features of the package, as well as provide guidance on how to use it effectively.

Basic tutorial

A basic tutorial is available here.

You can also refer to API for more information about different parameters.

Without ground filtering

from segment_lidar import samlidar, view

viewpoint = view.TopView()

model = samlidar.SamLidar(ckpt_path="sam_vit_h_4b8939.pth")
points = model.read("pointcloud.las")
labels, *_ = model.segment(points=points, view=view, image_path="raster.tif", labels_path="labeled.tif")
model.write(points=points, segment_ids=labels, save_path="segmented.las")

With ground filtering

from segment_lidar import samlidar, view

viewpoint = view.TopView()

model = samlidar.SamLidar(ckpt_path="sam_vit_h_4b8939.pth")
points = model.read("pointcloud.las")
cloud, non_ground, ground = model.csf(points)
labels, *_ = model.segment(points=cloud, view=view, image_path="raster.tif", labels_path="labeled.tif")
model.write(points=points, non_ground=non_ground, ground=ground, segment_ids=labels, save_path="segmented.las")

Note: The latest version of segment-lidar supports defining a custom pinhole camera, with or without interactive visualization, and save the view as an image. Please, refer to the documentation for more details.

Sample data

For testing purposes, you can download a sample here: pointcloud.las.

This data was retrieved from AHN-4. For more data, please visit GeoTiles.nl.

Model checkpoints

Click the links below to download the checkpoint for the corresponding model type.

Docker Image

segment-lidar is also available as Docker image.

These are the steps to run segment-lidar as a Docker container:

  1. First pull the image using the docker pull command:
docker pull yarroudh/segment-lidar
  1. To run the Docker container and mount your data and script file inside it, use the docker run command with the -v option to specify the path to the host directory and the path to the container directory where you want to mount the data folder. For example:
docker run -d -v ABSOLUTE_PATH_TO_HOST_DATA:/home/user yarroudh/segment-lidar

This command will start a Docker container in detached mode, mount the ABSOLUTE_PATH_TO_HOST_DATA directory on the host machine to the /home/user/data directory inside the container, and run the yarroudh/segment-lidar image. Do not change the path of the directory inside the container.

  1. Find the container ID and copy it. You can use the docker ps command to list all running containers and their IDs.
  2. Launch a command inside the container using docker exec, use the container ID or name and the command you want to run. For example:
docker exec CONTAINER_ID python SCRIPT_FILE
  1. To copy the output of the command from the container to a local path, use the docker cp command with the container ID or name, the path to the file inside the container, and the path to the destination on the host machine. For example:
docker cp CONTAINER_ID:/home/user/PATH_TO_OUTPUT PATH_ON_HOST_MACHINE
  1. Finally, after executing all the commands and copying the results to your local machine, you can stop the Docker container using the docker stop command followed by the container ID or name:
docker stop CONTAINER_ID

We would like to express our acknowledgments to the creators of:

Please, visit these repositories for more information about image raster automatic segmentation using SAM from Meta AI.

License

This software is under the BSD 3-Clause "New" or "Revised" license which is a permissive license that allows you almost unlimited freedom with the software so long as you include the BSD copyright and license notice in it. Please refer to the LICENSE file for more detailed information.

Citation

The use of open-source software repositories has become increasingly prevalent in scientific research. If you use this repository for your research, please make sure to cite it appropriately in your work. The recommended citation format for this repository is provided in the accompanying BibTeX citation. Additionally, please make sure to comply with any licensing terms and conditions associated with the use of this repository.

@misc{yarroudh:2023:samlidar,
  author = {Yarroudh, Anass},
  title = {LiDAR Automatic Unsupervised Segmentation using Segment-Anything Model (SAM) from Meta AI},
  year = {2023},
  howpublished = {GitHub Repository},
  url = {https://github.com/Yarroudh/segment-lidar}
}

Yarroudh, A. (2023). LiDAR Automatic Unsupervised Segmentation using Segment-Anything Model (SAM) from Meta AI [GitHub repository]. Retrieved from https://github.com/Yarroudh/segment-lidar

Author

This software was developped by Anass Yarroudh, a Research Engineer in the Geomatics Unit of the University of Liege. For more detailed information please contact us via ayarroudh@uliege.be, we are pleased to send you the necessary information.


Copyright © 2023, Geomatics Unit of ULiège. Released under BSD-3 Clause License.

Metadata

Release files for segment-lidar 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for segment-lidar 0.2.1
File Size Uploaded
segment-lidar-0.2.1.tar.gz 16.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for segment-lidar 0.2.1
File Interpreter ABI Platform
segment_lidar-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 30.6 kB

Release files / segment-lidar-0.2.1.tar.gz

Download URL segment-lidar-0.2.1.tar.gz
Size 16.5 kB
Tags Source
SHA-256 checksum
How to use checksums
181a35daa802fe2976a53932ad9122b766c2ea91f1bd771d93e3b03b7b6d7b42
BLAKE2b-256 checksum
How to use checksums
06c0e374af09ec0ec739f8e47eb9e8c4e845dc541426be226efc3f41307f3bb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / segment_lidar-0.2.1-py3-none-any.whl

Download URL segment_lidar-0.2.1-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
900d8d727b7359e36f17890039590507252c2ba63361f2b00a1018e1ee942439
BLAKE2b-256 checksum
How to use checksums
a131be7e704e77e98410f0abcbccef71ffc6493c8843da3d6920a480b65600b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page