Extract RGB values from point cloud data
rgb = readRGB(
[r g b] values from all points in the
pcloud, and returns them as
an n-by-3 matrix of n 3-D point coordinates.
If the point cloud does not contain the RGB field, this function displays an error.
To preserve the structure of the point cloud data, see Preserving Point Cloud Structure.
Read RGB Values from ROS Point Cloud Message
Load sample ROS messages including a ROS point cloud message,
Read the RGB values from the point cloud.
rgb = readRGB(ptcloud);
rgb — List of RGB values from point cloud
List of RGB values from point cloud, returned as a matrix. By default,
this is an n-by-3 matrix. If the point cloud object being
read has the
PreserveStructureOnRead property set to
true, the points are returned as an
h-by-w-by-3 matrix. For more
information, see Preserving Point Cloud Structure.
Point cloud data can be organized in either 1-D lists or in 2-D image styles. 2-D
image styles usually come from depth sensors or stereo cameras. The input
PointCloud2 object contains a
property that is either
Suppose that you set the property to
pcloud.PreserveStructureOnRead = true;
Now calling any read functions (
preserves the organizational structure of the point cloud. When you preserve the
structure, the output matrices are of size
m is the height, n is the width, and
d is the number of return values for each point. Otherwise, all
points are returned as an x-by-d list. This
structure can be preserved only if the point cloud is organized.
Version HistoryIntroduced in R2019b
R2021a: ROS Message Structure Functions
You can now create messages as structures with fields matching the message object properties. Using structures typically improves performance of creating, updating, and using ROS messages, but message fields are no longer validated when set. Message types and corresponding field values from the structures are validated when sent across the network.
To support message structures as inputs, new functions that operate on specialized ROS messages have been provided. These new functions are based on the existing object functions of message objects, but support ROS and ROS 2 message structures as inputs instead of message objects.
The object functions will be removed in a future release.
|Message Types||Object Function Name||New Function Name|