Introduction to Point Cloud Processing

How to create and visualize point clouds

Chayma Zatout
Better Programming

--

Photo by Henry Be on Unsplash

This is the 1st article of my “Point Cloud Processing” tutorial.

“Point Cloud Processing” tutorial is beginner-friendly in which we will simply introduce the point cloud processing pipeline from data preparation to data segmentation and classification.

In this tutorial, we will introduce point clouds and see how they can be created and visualized.

Table of contents:
· 1. Introduction
· 2. Point cloud generation
2.1 Random point cloud
2.2 Sampled point cloud
2.3 Point clouds from RGB-D data
· 3. Open3D and NumPy
3.1 From NumPy to Open3D
3.2 From Open3D to NumPy
· 4. Conclusion

1. Introduction

Point cloud applications are everywhere: robotics, autonomous vehicles, assistance systems, healthcare, etc. A point cloud is a 3D representation suitable for processing real-world data, especially when the geometry of the scene/objects is required, such as the distance, the shape and the size of objects.

A point cloud is a set of points that represents the scene in the real world or objects in space. It is a discrete representation of geometric objects and scenes. More formally, a point cloud PCD is a set of n points where each point Pi is represented by its 3D coordinates :

Note that some other features can be added to describe point clouds such as RGB colors, normals, etc. RGB colors, for example, can be added to provide color information.

2. Point cloud generation

Point clouds are typically generated using 3D scanners (laser scanners, time-of-flight scanners, and structured-light scanners) or from computer-aided design (CAD) models. In this tutorial, we will first create random point clouds and visualize them. Then we will generate it from 3D models by sampling points from the 3D surface using the Open3D library. Finally, we will see how they can be created from RGB-D data.

Let’s start by importing the libraries:

2.1 Random point cloud

The easiest way is to create a point cloud randomly. Note that we don’t usually create random points to be processed, except to create noise for GANs (Generative Adversarial Networks) for example.

Generally, point clouds are represented by (n × 3) arrays where n is the number of points. Let’s create a point cloud with 5 random points:

We can just print these points but it is not efficient especially if the number of points is large like in most applications. A better way is to display them in 3D space. Let’s visualize it using Matplotlib library:

Random point cloud visualization

2.2 Sampled point cloud

Sometimes processing 3D models directly takes time and memory. Therefore, sampling point clouds from their 3D surfaces is a potential solution. Let’s import the bunny model from the Open3D dataset:

Or import it after downloading it from this link:

Next, display the 3D model to see how it looks like. You can move the mouse to view from different view points.

The bunny 3D model

To sample a point cloud, several methods exist. In this example, we sample 1000 points uniformly from the imported mesh and visualize it:

The bunny point cloud

We can save the created point cloud in .ply format as follows:

2.3 Point clouds from RGB-D data

RGB-D data is collected using RGB-D sensors (such as Microsoft Kinect) which simultaneously provide an RGB image and a depth image. RGB-D sensors are involved in many applications such as indoor navigation, obstacle avoidance, etc. As the RGB image provides the pixel color, each pixel of the depth image indicates its distance from the camera.

Open3D provides a set of functions for RGB-D image processing. To create point clouds from RGB-D data using Open3D functions just import the two images, create an RGB-D image object and finally compute the point cloud as follows:

Colored point cloud generated from RGB-D image

3. Open3D and NumPy

Sometimes you will need to switch between Open3D and NumPy representations. For example, let’s say we want to convert a NumPy point cloud to an Open3D.PointCloud object for visualization, and visualize the 3D model of bunny using Matplotlib.

3.1 From NumPy to Open3D

In this example, we create 2000 random points using NumPy.random.rand() function that creates random samples from a uniform distribution over [0,1[. Then we create an Open3D.PointCloud object and set its Open3D.PointCloud.points feature to the random points using Open3D.utility.Vector3dVector() function.

Open3D visualization of a random point cloud

3.2 From Open3D to NumPy

Here, we first read the point cloud from a .ply file using Open3D.io.read_point_cloud() function that returns an Open3D.PointCloud object. After that, we only have to transform the Open3D.PointCloud.points feature that represents the points to a NumPy array using NumPy.asarray() function. Finally, we display the obtained array as we did above.

The bunny point cloud displayed using Matplotlib

4. Conclusion

In this tutorial, we learned how to create and visualize point clouds. In the tutorials that follow, we will learn how to process them. In the next tutorial, we will see how to compute in detail a point cloud from depth image and RGB-D data without using Open3D functions.

Thanks, I hope you enjoyed reading this. You can find the examples here in my GitHub repository. If you have any questions or suggestions feel free to leave me a comment below.

References

Image credits

All images and figures in this article whose source is not mentioned in the caption are by the author.

--

--

Passionate about writing tutorials in a simple and organized way. I write about computer vision and machine learning.