pcshow
Plot 3-D point cloud
Syntax
Description
pcshow(
displays
points specified by the xyzPoints
)xyzPoints
matrix.
pcshow(
displays
the point cloud stored in the file specified by filename
)filename
.
pcshow(___,
specifies options
using one or more name-value arguments in addition to any combination input of
arguments from previous syntaxes. For example, Name=Value
)ViewPlane="XY"
sets the plane from which to visualize the point cloud as the
xy-plane.
returns
the plot axes.ax
= pcshow(___)
Examples
Plot Spherical Point Cloud with Texture Mapping
Generate a sphere consisting of 600-by-600 faces.
numFaces = 600; [x,y,z] = sphere(numFaces);
Plot the sphere using the default color map.
figure; pcshow([x(:) y(:) z(:)]) title("Sphere with Default Color Map") xlabel("X") ylabel("Y") zlabel("Z")
Load and display an image for texture mapping.
I = im2double(imread("visionteam1.jpg"));
imshow(I)
Resize and flip the image in preparation for mapping the coordinates.
J = flipud(imresize(I,size(x)));
Plot the sphere with the image as a color texture.
pcshow([x(:) y(:) z(:)],reshape(J,[],3)) title("Sphere with Color Texture") xlabel("X") ylabel("Y") zlabel("Z")
Plot Lidar Point Cloud Based On Intensity
Load an organized lidar point cloud that includes intensity data.
ld = load("drivingLidarPoints.mat");
Plot the point cloud and label the figure. By default, the intensity is mapped to the jet
colormap.
figure pcshow(ld.ptCloud, ColorSource="Intensity") title("Lidar Point Cloud with Intensity") xlabel("X") ylabel("Y") zlabel("Z") colorbar(Color=[1 1 1]) colormap("winter")
Input Arguments
ptCloud
— Point cloud
pointCloud
object
Point cloud, specified as a pointCloud
object. The object
contains the locations, intensities, and RGB colors to render the point
cloud.
filename
— Point cloud filename
character vector | string scalar
xyzPoints
— Point cloud x-, y-, and z- locations
M-by-3 numeric matrix | M-by-N-by-3 numeric array
Point cloud x-, y-, and
z- locations, specified as either an
M-by-3 numeric matrix or an
M-by-N-by-3 numeric array. The
xyzPoints
argument contains M or
M-by-N points in the form
[x,y,z]. The
z values, which generally correspond to depth or
elevation, determine the color of each point. When you do not specify the
input color, the function maps each z value to a color in
the current colormap.
color
— Color for points in point cloud
RGB triplet | short name of color | long name of color | array of color names | cell array of color names | M-by-3 array | M-by-N-by-3 matrix
Color for points in the point cloud, specified as an RGB triplet, an M-by-3 matrix, an M-by-N-by-3 array, a short color name, a long color name, array of color names, or a cell array of color names. For details on color values, see the Color Value table.
For the
single
ordouble
data type, eachcolor
RGB value must be in the range [0, 1].For the
uint8
data type, eachcolor
RGB value must be in the range [0, 255].The function stores the
color
value as either an M-by-3 matrix or M-by-N-by-3 array. If you specify the color as a string or a 1-by-3 vector, the function converts it to one of these dimensions.
Color | Format | Example |
---|---|---|
Specify one color for all points | short or long color name |
|
1-by-3 vector (RGB triplet) |
| |
Specify a color for each point | string array of character vectors |
|
M-by-3 matrix, in which each row is an RGB triplet | 255 0 0 255 0 0 0 255 255 | |
M-by-N-by-3 array for an organized point cloud, containing RGB values for each point, where M-by-N is the size of the point cloud. |
|
colorMap
— Point cloud color map
M-by-1 vector | M-by-N matrix
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: ViewPlane="XY"
sets the plane to the x-y axes from
which to visualize the point cloud.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
MarkerSize
— Diameter of marker
6
(default) | positive scalar
Diameter of the marker, specified as a positive scalar. The value specifies the approximate diameter of the point marker. MATLAB graphics defines the unit as points. A marker size larger than 6 can reduce rendering performance.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
BackgroundColor
— Background color
[0 0 0]
(black) (default) | RGB triplet | hexadecimal color code | character vector
Background color, specified as an RGB triplet, hexadecimal color code, or a character vector that specifies a long or short color name.
Data Types: cell
| char
| uint8
| uint16
| int16
| double
| single
VerticalAxis
— Vertical axis
"Z"
(default) | "X"
| "Y"
Vertical axis, specified as "X"
,
"Y"
, or "Z"
. This value sets
the selected axis of the point cloud in the vertical direction.
VerticalAxisDir
— Vertical axis direction
"Up"
(default) | "Down"
Vertical axis direction, specified as "Up"
or
"Down"
.
Projection
— Camera projection for 3-D views
"perspective"
(default) | "orthographic"
Camera projection for 3-D views, specified as one of these values:
"perspective"
— Projects the viewing volume as the frustum of a pyramid (a pyramid whose apex has been cut off parallel to the base). Objects further from the camera appear smaller. Distance causes foreshortening, which enables you to perceive the depth of 3-D objects. This projection type is useful when you want to display realistic views of real objects. Perspective projection does not preserve the relative dimensions of objects. Instead, it displays a distant line segment smaller than a nearer line segment of the same length. Lines that are parallel in the data might not appear parallel in the scene."orthographic"
— This projection type maintains the correct relative dimensions of graphics objects regarding the distance of a given point from the viewer. Relative distance from the camera does not affect the size of objects. Lines that are parallel in the data parallel appear parallel on the screen. This projection type is useful when it is important to maintain the actual size of objects and the angles between objects.
ViewPlane
— Plane to visualize point cloud
"auto"
(default) | "XY"
| "YX"
| "XZ"
| "ZX"
| "YZ"
| "ZY"
Plane to visualize point cloud, specified as
"auto"
, "XY"
,
"YX"
, "XZ"
,
"ZX"
, "YZ"
, or
"ZY"
. The ViewPlane
argument
sets the line of sight from the camera, centered in the selected plane,
to the center of the plot.
ColorSource
— Point cloud property for colormap
"auto"
(default) | "X"
| "Y"
| "Z"
| "Intensity"
| "Color"
| "Row"
| "Column"
Point cloud property for colormap, specified as
"auto"
,"X"
,
"Y"
, "Z"
,
"Intensity"
, "Color"
,
"Row"
, "Column"
. The
pcshow
function uses the value of
ColorSource
to assign a colormap when rendering
the point cloud. The values use these properties:
"X"
— x-coordinates in theLocation
property of the input point cloud."Y"
— y-coordinates in theLocation
property of the input point cloud."Z"
— z-coordinates in theLocation
property of the input point cloud."Intensity"
—Intensity
property of the input point cloud."Color"
—Color
property of the input point cloud."Row"
— Row values of an organized point cloud."Column"
— Column values of an organized point cloud.
When you set ColorSource
to
"auto"
, the function sets the colormap depending
on which property values are available in the input point cloud
object:
Available Point Cloud Property | Color Source |
---|---|
Location only | Maps the z-value to a color value in the current colormap. |
Location and
Intensity | Maps the z-value to a color value in the current colormap. |
Location and
Color | Maps the color values to the current colormap. |
Location ,
Intensity , and
Color | Maps the color values to the current colormap. |
AxesVisibility
— State of axes visibility
"on"
or 1
(true
) (default) | "off"
or 0
(false
)
State of axes visibility, specified as "on"
or
"off"
, or as numeric or logical
0
(false
) or
1
(true
). A value of
"on"
is equivalent to true
,
and "off"
is equivalent to false
.
Thus, you can use the value of this property as a logical value. The
value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState
.
"on"
— Display the axes and its children."off"
— Hide the axes without deleting it. You still can access the properties of an invisible axes object. (Child objects such as lines remain visible.)
Parent
— Axes on which to display visualization
Axes
graphics object
Axes on which to display the visualization, specified as an
Axes
object. To create an Axes
object, use the axes
function. To display
the visualization in a new figure, leave Parent
unspecified.
Output Arguments
ax
— Plot axes
Axes
graphics object
Plot axes, returned as an axes
graphics object. Points
that are represented as NaN
or Inf
are
not included.
You can set the default center of rotation for the point cloud viewer as the axes center or as a point. Set the default behavior from the Computer Vision Toolbox Preferences.
A rotation axes (represented with red, blue, and green lines) appears at the center of rotation when rotating the point cloud.
More About
Axes Toolbar Operations
Keyboard shortcuts are enabled only for the rotate (default) mode. To view the axes toolbar operations, point to the figure and select one of these options. Click the Restore View icon to reset the display.
Feature | Description | ||||||
---|---|---|---|---|---|---|---|
Vertical Axis | Select an X-, Y-, or Z-direction to set the direction of that axis of the point cloud as the positive vertical direction. Use the keyboard arrow keys to move the point cloud with respect to the direction selected. | ||||||
View Plane | Select the viewing angle of the point cloud figure as the XY, YX, XZ, ZX, YZ, or ZY plane. | ||||||
Background Color | Display a color chart from which you can select a background color. | ||||||
Axes On/Off | Turn the display axes on or off. | ||||||
Projection | Select perspective or orthogonal view. | ||||||
Export |
| ||||||
Brush | Enable data brushing mode. | ||||||
Data Tips | View the point data values of a point by selecting it in the point cloud figure. The Data Tips display shows the x, y, and z values of the points. Point clouds for depth images and lidar contain these additional data properties:
| ||||||
Rotate 3D | Drag to rotate the point cloud figure. You can also right-click any point on the point cloud figure and select Rotate Around a Point to specify that point as the center of rotation for the figure. To return to axes rotation, right-click again and select Rotate Around Axes Center. While in Rotate 3D mode, you can also select the color source for the point cloud by right-clicking anywhere in the point cloud figure and selecting Color Source, and then selecting an option from the list. The figure applies the active colormap to the point cloud based on the values in the selected source. For a point cloud of only position data, the Color Source options are X, Y, Z, and User Specified. Point clouds for depth image and lidar data include these additional color source options:
| ||||||
Pan, Zoom in, and Zoom out | Maneuver the point cloud in the figure, or zoom the point cloud figure in or out. | ||||||
Restore View | Restore the original view of the axes. |
Move Camera Through Scene
To navigate into a point cloud and observe the scene, use these keyboard shortcuts:
Action | Keyboard Shortcut | Example |
---|---|---|
Move forward or backwards through the scene. The camera and the target can move. | w — Forward s — Backward |
|
Move left or right through the scene. The camera and the target can move. | a — Left d — Right | |
Look around the scene (pitch/yaw rotation of the camera). Camera position is fixed, target moves. | Up arrow — Camera pitches up Down arrow — Camera pitches down Left arrow — Camera turns left in yaw Right arrow — Camera turns right in yaw |
|
Roll the scene (roll rotation of the camera). | q — Camera moves clockwise. (Scene appears to move counterclockwise.) e — Camera moves counterclockwise. (Scene appears to move clockwise.) |
|
Rotate the scene (rotate the camera around the point cloud). Camera position changes, target is fixed. | Shift + Left or Right — Camera orbits horizontally around the point cloud. (Scene appears to stand still as camera moves externally around it horizontally.) Shift + Up or Down — Camera orbits vertically around the point cloud. (Scene appears to stand still as camera moves externally around it vertically.) |
|
Zoom in or out. | z — Zoom in x — Zoom out |
|
Look at a view plane. | 1 — XY 2 — YX 3 — XZ 4 — ZX 5 — YZ 6 — ZY Camera positioned in the selected plane with a line of sight to the center of the plot. |
|
Switch between rotate and pan. | Spacebar — Press and hold the spacebar to switch the interaction to pan. Release the spacebar to switch back to rotate. |
|
Rotate in X-, Y-, and Z- dimensions. | T — Adds rotate interaction in the third dimension. |
|
Color Values
Color Name | Short Name | RGB Triplet | Appearance |
---|---|---|---|
"red" | "r" | [1 0 0] | |
"green" | "g" | [0 1 0] | |
"blue" | "b" | [0 0 1] | |
"cyan"
| "c" | [0 1 1] | |
"magenta" | "m" | [1 0 1] | |
"yellow" | "y" | [1 1 0] | |
"black" | "k" | [0 0 0] | |
"white" | "w" | [1 1 1] |
Performance and Tips
To improve performance, the function automatically downsamples the rendered point cloud when you rotate, pan, or zoom in or out by clicking the mouse. Downsampling is not applied for zoom in or out by using the mouse scroll mechanism. When using data tips, the figure does not apply downsampling. The downsampling occurs only for rendering the point cloud and does not affect the saved points.
The keyboard shortcuts described in Move Camera Through Scene are not supported when loading a saved figure or for popped-out windows using Live Editor.
When you reload a saved figure, any action on the figure resets the vertical axis to the z-axis and in the up direction.
To visualize a large point cloud (greater than one million points), use the
pcviewer
object.
Version History
Introduced in R2015bR2022b: Default projection changed to perspective
The default projection for the camera 3-D view display has changed from
orthographic to perspective. You can use the new Projection
name-value argument to specify the projection as "perspective"
or
"orthographic"
. Prior to R2022b, the display rendered the
point cloud in an orthographic view only.
See Also
Objects
pcviewer
|pointCloud
|pcplayer
|planeModel
Functions
showShape
|pcshowpair
|plot3
|pcwrite
|pcread
|pcmerge
|scatter3
|reconstructScene
|triangulate
|pcdownsample
|pcfitplane
|pcdenoise
|pcregistericp
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)