简体   繁体   中英

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, ie

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, ie 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 ?

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);

在此处输入图片说明

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);

结果点云

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM