问题
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
?
回答1:
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);
回答2:
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);
来源:https://stackoverflow.com/questions/43898012/how-to-plot-a-3-d-pointcloud-object-with-intensity-information-in-matlab