Gentle Introduction to Preprocessing Point Clouds-pt. 2

Amnah Ebrahim
3 min readAug 31, 2023

--

This tutorial is in continuation to the following articles:

In this article we will be continuing our endeavor to look at different preprocessing techniques in segmentation such as:

  • The use of Convex Hulls
  • Segmentation using DBSCAN

Clustering and Segmentation of Point Cloud Data:

Segmentation

Segmentation refers to spatially grouping points with similar properties into homogenous regions.

Unlike our human ability to deduce patterns in data and make different observations, sensors lack the ability to mimick our human ability to group sets of elements through grouping objects that are formed by data points that share a pattern.

But why is segmentation useful?

Excellent question!

  • Firstly, it provides us with access to manipulates individual contents through higher-level represents known as segments.
  • Also, it allows for processing to be done at segmentations rather than individual point level, making computation much more efficient.
  • Finally, it provides us with the ability to computationally find relationships between different parts of the point cloud, which ofcourse isn’t possible by just viewing a point cloud.

Hence, through segmentation, we are enabling machines to computationally do what we otherwise take for granted, which is our human ability to understand our environment.

So let’s start with convex hulls!

Convex Hull

Now let’s take the chair from the previous example and compute the convex hull of it. But first…

What are Convex Hull and what are their applications?

Convex Hulls is the smallest convex polygon that can engulf the set of points in it’s space. If we have a set of pins as the points displayed below, and we would like the rubber band to snap tight arround them, the shape the rubber band makes is the convex hull.

Source: Click here
Brilliant’s Visualisation of Convex Hull

So..Back to Coding:

To compute the convex hull for a PCD, Open 3D usescompute_convex_hull as below:

hull, _ = chair.compute_convex_hull()
hull_ls = o3d.geometry.LineSet.create_from_triangle_mesh(hull)
hull_ls.paint_uniform_color((1, 0, 0))
o3d.visualization.draw_plotly([chair, hull_ls])

This convex hull is extremely useful in obstacle avoidance systems.

DBSCAN

Open3D utilises the DBSCAN clustering method, which is explained wonderfully in Analytics Vidhya’s blog.

To utilise DBSCAN we must specify two variables:

  • Epsilon: (radius of the circles)0.02
  • Minimum number of points to form a cluster: 10 points

The function of open3d will return the labels of the clusters where -1 is the noise.

with o3d.utility.VerbosityContextManager(
o3d.utility.VerbosityLevel.Debug) as cm:
labels = np.array(
pcd.cluster_dbscan(eps=0.02, min_points=10, print_progress=True))

To visualise, we will be using matplotlib’s colormap “get_cmap”.The colormap is generated from the ‘tab20’ colormap in Matplotlib, which maps the label values to RGB colors. Points that have a negative label value are assigned a zero color value.

import matplotlib.pyplot as plt
max_label = labels.max()
print(f"point cloud has {max_label + 1} clusters")
colors = plt.get_cmap("tab20")(labels / (max_label if max_label > 0 else 1))
colors[labels < 0] = 0
pcd.colors = o3d.utility.Vector3dVector(colors[:, :3])
o3d.visualization.draw_plotly([pcd],
zoom=0.455,
front=[-0.4999, -0.1659, -0.8499],
lookat=[2.1813, 2.0619, 2.0999],
up=[0.1204, -0.9852, 0.1215])

The max labels or clusters for this example are 10 clusters.

In the next article, we will be continuing our journey to understanding the general workflow of processing point cloud data tobuild maps through looking at:

  • Registration Methods
  • Iterative Closest Point
  • Global and Local Registration

--

--

Amnah Ebrahim

Electronics engineer passionate about electronics, machine learning, autonomous robotics, and natural language processing!