SoatDev IT Consulting
SoatDev IT Consulting
  • About us
  • Expertise
  • Services
  • How it works
  • Contact Us
  • News
  • June 16, 2023
  • Rss Fetcher

The beginning of your journey into the world of advanced geospatial analysis

Photo by Joshua Aragon on Unsplash

In the ever-evolving field of geospatial analysis, the processing of aerial LiDAR data has always presented unique challenges. Extracting valuable insights and actionable information from vast volumes of point cloud data requires advanced techniques and specialized tools. However, a groundbreaking package has emerged, set to transform how we approach this complex task. Enter segment-lidar, a cutting-edge software package meticulously designed to revolutionize unsupervised instance segmentation of aerial LiDAR data.

The power behind segment-lidar lies in its fusion of two remarkable innovations: Segment-Anything Model (SAM), a groundbreaking algorithm developed by Meta AI, and segment-geospatial package from Open Geospatial Solutions. By combining these two powerful tools, segment-lidar offers a solution for researchers, developers, and geospatial data experts, unlocking a world of possibilities in the automatic processing of aerial LiDAR data.

This comprehensive tutorial will guide you through applying the powerful segment-lidar package for unsupervised instance segmentation of aerial LiDAR data. By following these instructions, you will gain hands-on experience in leveraging segment-lidar capabilities and unlocking valuable insights from your LiDAR datasets.

Results of segment-lidar on AHN-4 LiDAR dataset

Prerequisites

Before installing segment-lidar, you need to create an environment by running the following commands:

conda create -n samlidar python=3.9
conda activate samlidar

This command will create a new Conda environment named samlidar. We recommend using Python 3.9 but feel free to test with other versions.

Please note that using a Conda environment is not mandatory but highly recommended. Alternatively, you can use virtualenv.

Now, you can easily install segment-lidar from PyPI using the following command:

pip install segment-lidar

Or, you can install it from the source with this code:

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

To make sure that segment-lidar is installed correctly, you can run the following command:

python -c "import segment_lidar; print(segment_lidar.__version__)"

If the installation is successful, you should see the version you installed.

Sample Data

For testing purposes, you can download sample data here: pointcloud.las. This data was retrieved from AHN-4. For more data, please visit AHN-Viewer.

You also need to download the checkpoint for the corresponding Segment-Anything model (SAM) type:

  • Default or vit_h: ViT-H SAM model.
  • vit_l: ViT-L SAM model.
  • vit_b: ViT-B SAM model.

Basic Usage

  • Import the necessary module:
from segment_lidar import samlidar
  • Create an instance of the SamLidar class and specify the path to the checkpoint file ckpt_path when instantiating the class:
model = samlidar.SamLidar(ckpt_path="sam_vit_h_4b8939.pth")
  • Read the point cloud data from the .las/.laz file using the read method of the SamLidar instance. Provide the path to the point cloud file, pointcloud.las, as an argument:
points = model.read("pointcloud.las")
  • Apply the Cloth Simulation Filter (CSF) algorithm for ground filtering using the csf method of the SamLidar instance. This method returns the filtered point cloud cloud, the non-ground non_ground, and the ground ground indices:
cloud, non_ground, ground = model.csf(points)
  • Perform segmentation using the segment method of the SamLidar instance. This method requires the filtered point cloud cloud as input, and you can optionally provide an image path image_path and labels path labels_path to save the segmentation results as an image and labels, respectively. The segment method returns the segmentation labels:
labels, *_ = model.segment(points=cloud, image_path="raster.tif", labels_path="labeled.tif")
  • Save results to the .las/.laz file using the write method of the SamLidar instance:
model.write(points=points, non_ground=non_ground, ground=ground, segment_ids=labels, save_path="segmented.las")

Now, the entire code should look like this:

from segment_lidar import samlidar

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, 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")

The resulting point cloud contains a new scalar field called segment_id. For visualization and further processing, we recommend using CloudCompare.

Configuration

The segment_lidar module provides a set of parameters that can be used to configure the segmentation process. When instantiating the class, these parameters are passed to the SamLidar class as arguments.

Here is an example of how to configure the parameters:

model = samlidar.SamLidar(ckpt_path="sam_vit_h_4b8939.pth",
algorithm="segment-geo-spatial",
model_type="vit_h",
resolution=0.5,
sam_kwargs=True)

Additionally, the parameters of segment-anything parameters can be configured as follows:

model.mask.crop_n_layers = 1
model.mask.crop_n_points_downscale_factor = 2
model.mask.min_mask_region_area = 500
model.mask.points_per_side = 10
model.mask.pred_iou_thresh = 0.90
model.mask.stability_score_thresh = 0.92

Please, refer to the segment-anything repository for more details about these parameters. See the complete arguments list of the SamLidar class here.

This tutorial has provided a valuable introduction to the capabilities of segment-lidar for unsupervised instance segmentation of aerial LiDAR data. However, this is just the beginning of your journey into the world of advanced geospatial analysis. To delve deeper into the functionalities, explore additional features, and discover the latest updates, we encourage you to consult the comprehensive documentation accompanying the segment-lidar package.

In addition to the documentation, we recommend visiting the official GitHub repository of segment-lidar. Here, you can find the most up-to-date source code, contribute to the development of the package, and connect with a vibrant community of users and developers passionate about 3D geospatial analysis.

The GitHub repository serves as a hub for collaboration, knowledge sharing, and staying informed about the latest advancements in the field.


Introducing Segment-Lidar: Revolutionizing Unsupervised Instance Segmentation of Aerial LiDAR Data was originally published in Better Programming on Medium, where people are continuing the conversation by highlighting and responding to this story.

Previous Post
Next Post

Recent Posts

  • TechCrunch Week in Review: Coinbase gets hacked
  • Epic Games asks judge to force Apple to approve Fortnite
  • Y Combinator startup Firecrawl is ready to pay $1M to hire three AI agents as employees
  • Build, don’t bind: Accel’s Sonali De Rycker on Europe’s AI crossroads
  • OpenAI’s planned data center in Abu Dhabi would be bigger than Monaco

Categories

  • Industry News
  • Programming
  • RSS Fetched Articles
  • Uncategorized

Archives

  • May 2025
  • April 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023

Tap into the power of Microservices, MVC Architecture, Cloud, Containers, UML, and Scrum methodologies to bolster your project planning, execution, and application development processes.

Solutions

  • IT Consultation
  • Agile Transformation
  • Software Development
  • DevOps & CI/CD

Regions Covered

  • Montreal
  • New York
  • Paris
  • Mauritius
  • Abidjan
  • Dakar

Subscribe to Newsletter

Join our monthly newsletter subscribers to get the latest news and insights.

© Copyright 2023. All Rights Reserved by Soatdev IT Consulting Inc.