hbaderts
hbaderts

Reputation: 14371

How to plot a 3-D pointCloud object with Intensity information in MATLAB?

I am using the MATLAB pointCloud class for working with and displaying 3-D point clouds. I have the coordinates of each point in x-, y-, and z-dimension, as well as a corresponding grayscale intensity value. For example, see the following test data:

x = [0,   1;   0,   1];
y = [0,   0;   1,   1];
z = [0,   0;   0,   0];
c = [0, 1/3; 2/3,   1];

The corresponding pointCloud object is created with

ptCloud = pointCloud(cat(3, x, y, z), 'Intensity', c);

Now I want to plot the point cloud using the pcshow command, i.e.

pcshow(ptCloud, 'MarkerSize', 1000);

Note: the 'MarkerSize' is only for this example, so the four points are clearly visible.

This, however, doesn't take the intensity information into account - as stated in the documentation, this takes the color information of the point cloud object, which doesn't exist in my case. The pointCloud object only allows to save RGB values for each pixel in the color field, i.e. grayscale intensities are not possible.

The pcshow function can also take an xyz array and the corresponding color information as input instead of a pointCloud object. Then, using the grayscale intensity as color information is possible and works as expected:

pcshow(cat(3, x, y, z), c, 'MarkerSize', 1000);

However, I want to keep working with pointCloud objects and not fall back to multiple arrays per frame. How can I use the Intensity information of a pointCloud object in pcshow?

Upvotes: 1

Views: 5034

Answers (2)

hbaderts
hbaderts

Reputation: 14371

The most recent MATLAB versions (at least R2018a) support this behavior out-of-the box. As described in the documentation, for a point cloud object with Location and Intensity information, the intensity value is mapped to a color using the current color map.

So the following code snippet does work as expected in more recent MATLAB versions:

x = [0,   1;   0,   1];
y = [0,   0;   1,   1];
z = [0,   0;   0,   0];
c = [0, 1/3; 2/3,   1];

ptCloud = pointCloud(cat(3, x, y, z), 'Intensity', c);
pcshow(ptCloud, 'MarkerSize', 1000);

resulting point cloud

Upvotes: 0

user2999345
user2999345

Reputation: 4195

You can use repmat on the 3rd dimension of c to create gray RGB color vectors, and then use 'Color' property of pointCloud:

x = [0,   1;   0,   1];
y = [0,   0;   1,   1];
z = [0,   0;   0,   0];
c = [0, 1/3; 2/3,   1];
% convert grayscale intensities to gray rgb values
C = repmat(c,[1 1 3]);
% plot colored pointcloud
ptCloud = pointCloud(cat(3, x, y, z),'Color',C);
pcshow(ptCloud, 'MarkerSize', 1000);

enter image description here

Upvotes: 2

Related Questions